fix(config): share local config across git worktrees
What does this MR do and why?
LocalConfigDir resolved through git rev-parse --git-dir, which in a linked worktree is .git/worktrees/<name>. Local config set in the main checkout was therefore invisible in every worktree, and each new worktree started empty and silently fell back to global.
This resolves through git rev-parse --git-common-dir instead, so one repository has one local config. Git shares .git/config the same way and makes per-worktree config opt-in, and these keys describe the repository rather than the checkout. Stacks were moved to the common dir for the same reason in 0a119c022.
References
Closes #8568 (closed)
Prior art in the same repository: #8355 (closed) moved stacks to the common dir. The per-worktree location came from #7872 (closed), which this keeps available as an existing-file override rather than the default.
Differences
Before: in a linked worktree, glab config get read .git/worktrees/<name>/glab-cli/config.yml and saw none of the repository's config.
After: it reads .git/glab-cli/config.yml, the same file the main checkout writes.
A worktree that already carries its own file keeps using it, so a config written before this change still applies where it was written. A normal checkout is unaffected, because both flags resolve to the same directory, and a submodule keeps its own under .git/modules/<name>.
Two details worth a reviewer's eye
git answers --git-common-dir with a relative, forward-slash path where it answers --git-dir with an absolute one, when run from a subdirectory:
$ cd a/b
$ git rev-parse --git-dir
C:/.../repo/.git
$ git rev-parse --git-common-dir
../../.gitThe old code always went through filepath.Rel, which normalised separators. The relative branch now cleans the result to the platform separator, otherwise Test_LocalConfigDir fails on Windows with ../../.git against ..\..\.git.
CheckPathExists returns info.IsDir(), so it reports only directories. The backwards-compatible lookup uses CheckFileExists instead. My first attempt used the wrong one and the existing-file override silently never fired.
How to set up and validate locally
End to end, which is the reproduction from the issue:
go build -o /tmp/glab ./cmd/glab
mkdir -p /tmp/repro/main && cd /tmp/repro/main
git init -q . && git commit -q --allow-empty -m init
/tmp/glab config set editor main-only-editor
git worktree add -q --detach ../wt && cd ../wt
/tmp/glab config get editor## MR acceptance checklist
- [x] Tests added, verified to fail without the fix
- [x] Reproduced end to end against binaries built from this branch and from `main`
- [x] Existing per-worktree files keep working
- [x] Packages that share `GitDir` pass unchanged
- [x] Conforms to the code review guidelines