Subject: Re: [PATCH v3 1/1] git-gui: handle missing worktree and separated gitdir

From: Mark Levedahl <[email-masked]>
Date: Thu, 7 May 2026 01:09:17 -0400

On 5/6/26 10:05 AM, Mark Levedahl wrote:
>
> On 5/6/26 8:57 AM, Johannes Sixt wrote:
>> Am 06.05.26 um 13:27 schrieb Mark Levedahl:
>>> A git repository (gitdir) can have config.bare true | false | not set
>>> git rev-parse --is-bare-repository tells you that whatever gitdir is discovered from the
>>> current directory has core.bare==true. This happens whether the call is from inside the
>>> gitdir, or in the parent dir of a gitdir named '.git', or in a directory containing a
>>> symlink or a gitfile link to the gitdir. This call never tells you what directory you are
>>> actually in.
>> OK. But how does "find out which directory we are in" come into play
>> here? If we find a bare repository, we do not need a worktree. If we are
>> in a non-bare repository, we can find the worktree with `rev-parse
>> --show-toplevel`.
The influence of config variable core.bare in a git repository breaks the design I
contemplated using rev-parse --is-inside-work-tree. core.bare is a strange tri-state item,
usually only set if the repository is explicitly bare. With core.bare undefined, rev-parse
can give different answers inside and outside a gitdir. For instance
      rev-parse --is-bare-repository gives true inside a repository, and false outside,
--is-inside-work-tree is also influenced by core.bare, so results cannot be interpreted as
I initially thought.

Anyway, after some experiments, the minimal sufficient tests I find for blame|browser and
gui|citool are different:

- blame|browser need a readable gitdir, and do not need a worktree. The current directory
can be inside the gitdir, core.bare is irrelevant.

    a sufficient startup test:

        git rev-parse --git-dir returns the name of a gitdir, rather than throwing an error.
               core.bare and being inside/outside of the gitdir do affect error / no error.
                (the return value may be a relative path, so can depend upon current
directory)

    only GIT_DIR should be exported. GIT_WORK_TREE should not be in env.

- gui|citool, require a gitdir, a worktree outside the gitdir, and core.bare is not true

    a sufficient and minimal startup test:

        git rev-parse --show-toplevel returns the worktree root, rather than throwing an
error.
                core.bare = true in the gitdir will cause error in the above.
                being inside the gitdir causes error in the above.

        But, starting in a .git directory supporting a worktree is allowed by the fallback
logic

        git rev-parse --git-dir returns '.', (current dir is the root of the gitdir),
rather than throwing an error.
        the current directory is named ".git", meaning the parent dir is this gitdir's
worktree if core.bare is not true
        git -C .. rev-parse --show-toplevel  returns the worktree root: (will throw an
error if core.bare is true)

    the current directory should be changed to the worktree root.
    GIT_DIR and GIT_WORK_TREE should be exported to env.

Mark