Re: [RFC PATCH 3/3] setup: communicate why a directory is not a valid git directory
- From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
- Date
- Sep 25, 2026, 14:33 UTC
- Message-ID
- <b27162ed-0c62-4ef0-b125-4340517e0d50@gmail.com>
- In-Reply-To
- <xmqq7bkaz45e.fsf@gitster.g>
On 9/25/26 03:46, Junio C Hamano wrote:
Show 13 quoted lines
> Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
>
>> + strbuf_addf(&die_msg, _("not a git repository: '%s'"), gitdirenv);
>> + strbuf_addch(&die_msg, '\n');
>> + strbuf_addf(&die_msg, _("reason: %s"), invalid_gitdir_reason.buf);
>> + die("%s", die_msg.buf);
>> +
>> + strbuf_release(&die_msg);
>
> You just called die(); nobody will execute this strbuf_release() for
> you, and because die() is marked with NORETURN, smart enough compilers
> would scold you for introducing dead code.
>Oops. It should indeed warn me. I did a quick check and seems gcc (which I was using) lost its ability to report this long ago[1]. Sad. Clang clearly reports this.
[1]: https://gcc.gnu.org/legacy-ml/gcc-help/2011-05/msg00360.html
Show 8 quoted lines
> Why are you lego-assembling localized message yourself, instead of
> doing something like ...
>
> die(_("not a git repository: '%s'\nreason: %s"),
> gitdirenv, invalid_gitdir_reason.buf);
>
> ... which is what is usually done?
> That was my attempt at trying to save translators some work of translating the "not a git repository" part. I was thinking this lego was not a problem as it was not so complex. If we just want to avoid legos totally, I'm cool with doing it the usual way.
-- Sivaraam