[Bug]: a stray .DS_Store in .git/worktrees makes every gh stack command fail
Describe the bug
A regular file inside .git/worktrees/ makes every gh stack command fail. On macOS, Finder drops a .DS_Store there as soon as someone opens the directory, so a repo that uses worktrees can end up with one without anyone noticing.
From the error, the state migration treats every entry of .git/worktrees/ as a worktree admin dir and gives up on the first one that isn't a directory. Skipping non-directories there would be enough.
Affected command
gh stack link (also gh stack view, gh stack add)
gh-stack version
gh stack version 0.2.1
GitHub CLI version
gh version 2.102.1 (2026-10-20)
Operating system
macOS 27.0.1
Shell
zsh
Steps to reproduce
git init -b main repo && cd repo
git commit --allow-empty -m init
git worktree add ../wt -b feature
touch .git/worktrees/.DS_Store
gh stack view
gh stack add test-branch
No remote is needed. I hit it on a real repo first, running gh stack link over three pushed branches.
Expected behavior
Files that aren't directories in .git/worktrees/ are skipped, and the command runs.
Actual behavior
The command fails before it does anything. Removing the .DS_Store fixes it.
Terminal output
$ gh stack view
✗ checking legacy stack state: worktree administration path "/…/repo/.git/worktrees/.DS_Store" is not a directory
$ gh stack add test-branch
✗ migrating stack state: worktree administration path "/…/repo/.git/worktrees/.DS_Store" is not a directory
Preflight checks
- [x] I searched the existing issues for duplicates.
- [x] I ran
gh extension upgrade stackand reproduced this issue on the latest stable release.
— printed by Claude Code, signed by me.
I dug into this while working on a fix — the root cause is in the legacy state migration: legacyCatalogs in internal/stack/migration.go treats every entry of .git/worktrees/ as a worktree administration directory and fails on the first entry that is not one (worktree administration path %q is not a directory). Any stray file dropped there — for example the .DS_Store that Finder creates the moment the directory is opened on macOS — makes every gh stack command fail until it is removed by hand.
A fix is prepared and verified at Lushiyao5/gh-stack@b6081e2 (branch fix/skip-stray-worktree-admin-files):
- regular files are skipped while scanning for legacy catalogs, matching how
defaultOps.worktreeGitDirsalready treats the same directory; - every other non-directory entry, including symlinked administration entries, still surfaces the existing error instead of being silently skipped;
TestLegacyState_MetadataErrorsis updated accordingly andTestLegacyState_SkipsStrayFilesInAdministrationDirectorycovers both a stray file alone and a stray file alongside a migratable catalog;- reproduced with the exact steps from this issue against a build of
main, confirmed fixed after the change;go vet ./...and theinternal/stacksuite pass.
I attempted to open a pull request, but this repository limits pull requests to collaborators. Happy to open one if that ever changes — otherwise please feel free to take the branch directly.