gitdir: use relative path
at the moment, the .git for git worktree is a absolute path.
It means if we move the main folder repo and its worktree repo.branch1 elsewhere, they don't work anymore.
this could be fixed by changing:
repo.branch1]$ cat .git
gitdir: /absolute/path/to/repo/.git/worktrees/repo.branch1
to:
repo.branch1]$ cat .git
gitdir: ../repo/.git/worktrees/repo.branch1
Thanks for the suggestion! I searched the codebase and worktrunk currently always passes absolute paths to git worktree add without the --relative-paths flag.
Git itself added support for this via git worktree add --relative-paths and the worktree.useRelativePaths config option (available in Git 2.48.0+). Worktrunk could potentially forward this flag or respect the git config when creating worktrees.
As a workaround, you can set worktree.useRelativePaths = true in your git config (git config worktree.useRelativePaths true), and git should use relative paths automatically — though I haven't verified whether worktrunk's path handling (which canonicalizes paths internally) interacts cleanly with that.
I'll leave it for a maintainer to evaluate and prioritize.
As a workaround, you can set
worktree.useRelativePaths = truein your git config (git config worktree.useRelativePaths true), and git should use relative paths automatically — though I haven't verified whether worktrunk's path handling (which canonicalizes paths internally) interacts cleanly with that.
let's make a test for this
Added a test in #1631 — it enables worktree.useRelativePaths = true, creates a worktree via wt switch --create, asserts the .git file contains a relative gitdir: path, then verifies wt list and wt switch both work correctly.
Everything passes — worktrunk's path handling (which canonicalizes internally) is compatible with relative worktree paths out of the box.
@saidelike is that sufficient? it seems we do the same as git and so changing git configs is the way?