Subject: Re: [PATCH v1 11/11] git-gui: add gui and pick as explicit subcommands

From: Mark Levedahl <[email-masked]>
Date: Tue, 19 May 2026 14:45:45 -0400

On 5/19/26 4:21 AM, Johannes Sixt wrote:
> Am 16.05.26 um 17:42 
>
>
> I think I would be happier with the structure
>
> if not subcommand pick
>     discover gitdir
>     if error
>         set subcommand pick
>
> if subcommand pick
>     pick_repo
>     set subcommand gui
>
> because this clarifies that pick_repo must erase all current traces of
> GIT_DIR and GIT_WORK_TREE from the envionment and must complete with a
> valid setup.
>
> With the structure in the proposed patch
>
> if subcommand pick
>     pick_repo
>     set subcommand gui
>
> discover gitdir
> if error
>     pick_repo
>
> we still need the same operation of pick_repo, but after it runs due to
> a pick command, we go into "discover gitdir" mode in an already modified
> environment, something that does not happen if pick_repo runs due to the
> error in the gitdir discovery.
>
> -- Hannes
>

What I have now is

if (enabled gitdir discovery) {
    discover gitdir
    maybe an error occurs and gitdir remains {}
}

if (enabled pick && gitdir eq {}) {
    unset GIT_DIR .. (just to be friendly, could throw an error instead...)
    pick
    discover gitdir to VALIDATE pick gave us a good thing
}

if no gitdir {
    error No Repository
}

then on to worktree discovery (which also validates what pick returns as pick may not have
done so).

So, we can independently enable normal discovery or pick, and with both enabled pick can
be used to recover from an error in normal discovery. Either way, there is only one block
of code running pick, it is not a separate proc invoked multiple places. I hope this
scratches your itch.

Still scrubbing things, should send out in a day or two.

Mark