{"thread":{"id":"62310","subject":"`git worktree list` when bare repository is named `.git`","startedAt":"2024-10-11T01:12:31Z","lastAt":"2024-10-11T01:12:31Z","messageCount":1,"participants":["Rebecca Turner"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"504774","messageId":"8f961645-2b70-4d45-a9f9-72e71c07bc11@app.fastmail.com","threadId":"62310","inReplyTo":null,"subject":"`git worktree list` when bare repository is named `.git`","fromName":"Rebecca Turner","fromEmail":"rbt@fastmail.com","sentAt":"2024-10-11T01:12:09Z","receivedAt":"2024-10-11T01:12:31Z","isPatch":false,"sender":{"key":"rbt@fastmail.com","avatar":null},"body":"It seems that `.git` is always stripped from the `git worktree list` output (including in `--porcelain` mode). This becomes relevant with bare repositories. Here is a bare repository functioning as expected:\n\n$ mkdir bare1\n$ cd bare1\n$ git init --bare\nInitialized empty Git repository in /private/tmp/bare1/\n$ git worktree list\n/private/tmp/bare1  (bare)\n\nBut if we create a bare repository in a directory named `.git`, `git worktree list` displays the parent directory as the worktree, even though `git status` doesn't recognize it as a worktree:\n\n$ mkdir -p bare2/.git\n$ cd bare2/.git\n$ git init --bare\nInitialized empty Git repository in /private/tmp/bare2/.git/\n$ git worktree list\n/private/tmp/bare2  (bare)\n$ cd /tmp/bare2\n$ git status\nfatal: this operation must be run in a work tree\n\nHowever, Git _will_ recognize the parent directory (/tmp/bare2) as a Git repository for the purposes of commands like `git rev-parse --git-dir`. I suspect this can be fixed in `get_main_worktree` by only stripping a `.git` suffix from the path if the main worktree is not bare.\n"}]}