Subject: Re: [PATCH v1] builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE

From: Junio C Hamano <[email-masked]>
Date: Fri, 13 Mar 2026 09:03:29 -0700

Tian Yuchen <[email-masked]> writes:

>> That is, can `repo` ever be `NULL`? For that
>> you have to look at "git.c" and figure out whether or not the command
>> requires a repository to exist.
> I checked git.c and found that there is:
>
> { "mktree", cmd_mktree, RUN_SETUP }
>
> in commands[]. If my understanding is correct, before cmd_mktree is 
> called, setup_git_directory() must have been fully executed. In that 
> case, if the current directory isn't a valid repository (NULL), it 
> should have already exited at an earlier stage, right?

There is one corner case; upon "git foo -h", your cmd_foo() will get
repo==NULL when the command is run outside a repository.  As long as
your cmd_foo() asks parse_options() to react to "-h" (which gives
the help message and then exits) before it uses repo assuming it
cannot be NULL, you are safe.