{"thread":{"id":"66972","subject":"Main worktree path reported by git worktree list with --separate-git-dir","startedAt":"2026-12-02T14:33:25Z","lastAt":"2026-12-02T14:33:25Z","messageCount":1,"participants":["keith.hughitt@gmail.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"559892","messageId":"CAOJcpR-W7nD1THbqrU4LniUWGu486-rOO7UEto1K720aNRj+CQ@mail.gmail.com","threadId":"66972","inReplyTo":null,"subject":"Main worktree path reported by git worktree list with --separate-git-dir","fromName":"","fromEmail":"keith.hughitt@gmail.com","sentAt":"2026-12-02T14:33:25Z","receivedAt":"2026-12-02T14:33:25Z","isPatch":false,"sender":{"key":"keith.hughitt@gmail.com","avatar":null},"body":"With separate Git metadata, git worktree list reports a path derived from\nthe metadata directory as the main worktree, even when core.worktree\nspecifies the actual checkout. Is that the intended behavior?\n\nSystem information:\n\n    Linux 7.3.6-arch1-1 x86_64\n    git version 2.56.1\n    cpu: x86_64\n    built from commit: 03b41523c576f26ad34085378717a0c1b287470f\n    sizeof-long: 8\n    sizeof-size_t: 8\n    shell-path: /bin/sh\n    rust: enabled\n    feature: fsmonitor--daemon\n    gettext: enabled\n    libcurl: 8.23.0\n    OpenSSL: OpenSSL 4.1.0 23 Oct 2026\n    zlib-ng: 2.3.3\n    SHA-1: SHA1_DC\n    SHA-256: SHA256_BLK\n    default-ref-format: files\n    default-hash: sha1\n\nReproduction:\n\nRun with sh. The script creates two temporary repositories and removes\nthem on exit. It uses the physical temp path so the assertions also work\nwhen TMPDIR is a symlink.\n\n    set -eu\n    fixture=$(cd \"$(mktemp -d)\" && pwd -P)\n    trap 'rm -rf -- \"$fixture\"' EXIT HUP INT TERM\n\n    fixture_git () {\n        env -i PATH=\"$PATH\" HOME=\"$fixture\" GIT_CONFIG_GLOBAL=/dev/null \\\n            GIT_CONFIG_NOSYSTEM=1 git -c core.hooksPath=/dev/null \"$@\"\n    }\n\n    seed_fixture () {\n        fixture_git init -q -b main --separate-git-dir \"$2\" \"$1\"\n        test \"$(fixture_git -C \"$1\" rev-parse --show-toplevel)\" = \"$1\"\n        test \"$(fixture_git -C \"$1\" rev-parse --absolute-git-dir)\" = \"$2\"\n        fixture_git -C \"$1\" -c user.name=Fixture \\\n            -c user.email=fixture@example.invalid \\\n            commit -q --allow-empty -m fixture\n        fixture_git -C \"$1\" worktree add -q --detach \"$3\"\n    }\n\n    seed_fixture \"$fixture/primary\" \"$fixture/metadata\" \"$fixture/linked\"\n    fixture_git -C \"$fixture/primary\" worktree list --porcelain\n    fixture_git -C \"$fixture/linked\" worktree list --porcelain\n    fixture_git -C \"$fixture/primary\" config core.worktree \"$fixture/primary\"\n    fixture_git -C \"$fixture/linked\" worktree list --porcelain\n    fixture_git -C \"$fixture/metadata\" rev-parse --show-toplevel\n    fixture_git -C \"$fixture/linked\" worktree list --porcelain -z |\n        tr '\\000' '\\n' | sed -n '1p'\n\n    variant=\"$fixture/variant\"\n    mkdir -p \"$variant/store\"\n    seed_fixture \"$variant/primary\" \"$variant/store/.git\" \"$variant/linked\"\n    fixture_git -C \"$variant/linked\" worktree list --porcelain\n    fixture_git -C \"$variant/store\" rev-parse --show-toplevel\n    fixture_git -C \"$variant/primary\" config core.worktree \"$variant/primary\"\n    fixture_git -C \"$variant/linked\" worktree list --porcelain\n    fixture_git -C \"$variant/store\" rev-parse --show-toplevel\n\nExpected behavior:\n\nThe git-worktree manual says the main worktree is listed first. I'd\nexpect the first record to report the checkout path when it is known from\ncore.worktree, or the manual to explain how the listed path is chosen\nwhen the Git directory is separate.\n\nActual behavior:\n\nThe first three listings begin with \"worktree <fixture>/metadata\". The\nlinked record correctly names \"<fixture>/linked\". After setting\ncore.worktree, rev-parse prints \"<fixture>/primary\" and the first\nNUL-delimited record still says \"worktree <fixture>/metadata\".\n\nIn the variant, both listings begin with \"worktree <fixture>/variant/store\".\nBefore core.worktree is set, rev-parse run in store also prints\n\"<fixture>/variant/store\". Afterward it prints \"<fixture>/variant/primary\".\nThis means that checking whether the listed path is itself a Git\ntop level can still identify the wrong directory.\n\nSource and prior search:\n\nget_main_worktree() takes the real path of repo_get_common_dir() and\nstrips any trailing /.git on both master and next. The common directory\nhas no back-pointer to the main checkout, so Git appears to infer the\npath from the metadata location. In these fixtures core.worktree is the\nexplicit record of the checkout path once configured.\n\nhttps://github.com/git/git/blob/master/worktree.c\nhttps://github.com/git/git/blob/next/worktree.c\nhttps://git-scm.com/docs/git-worktree\n\nSearches of Git/GitGitGadget issues and pull requests, indexed Git list\ndiscussions, and the 2.54 through 2.56.1 release notes found no matching\ncorrection. PR 2208 concerns repo info path keys:\nhttps://github.com/git/git/pull/2208\n\nThe search could have missed an earlier discussion. The branch comparison\nis from source inspection. The reproduction above ran on Git 2.56.1.\n\nShould git worktree list honor core.worktree for the main entry when set?\nIf the entry is intended to keep its current meaning, what command\nshould consumers use to identify the main checkout in this layout?\n\n"}]}