worktrunk
worktrunk copied to clipboard
`copy-ignored` copies untracked symlinks as regular files
My repo has gitignore'd symlinks that point to other untracked files, specifically in node_modules in a Yarn monorepo. wt step copy-ignored copies these as regular files rather than as symlinks, which breaks Yarn.
Steps to repro:
$ git init test_repo
$ cd test_repo
$ git commit --allow-empty -m "initial commit"
$ touch test_file
$ ln -s test_file symlink_to_test_file
$ echo -e "test_file\nsymlink_to_test_file" > .gitignore
# verify that we have a regular file and a symlink
$ ls -l
total 0
lrwxrwxrwx 1 shawn users 9 Mar 13 09:25 symlink_to_test_file -> test_file
-rw-r--r-- 1 shawn users 0 Mar 13 09:25 test_file
$ wt switch --create new_branch
$ wt step copy-ignored
# both are now regular files
$ ls -l
total 0
-rw-r--r-- 1 shawn users 0 Mar 13 09:28 symlink_to_test_file
-rw-r--r-- 1 shawn users 0 Mar 13 09:28 test_file
Thanks for reporting this! I was able to reproduce the issue and identified the root cause: when git ls-files lists a symlink as a top-level entry (not inside a directory), copy-ignored used reflink_or_copy which follows the symlink and copies the target file contents as a regular file instead of preserving the symlink.
I've opened #1489 with a fix. A maintainer will review it shortly.