From: Patrick Steinhardt Date: Mon, 16 Nov 2026 06:35:26 GMT Subject: Re: [PATCH] promisor-remote: fix crash without a repository Message-ID: In-Reply-To: On Fri, Nov 13, 2026 at 11:42:47AM -0800, Junio C Hamano wrote: > Christian Couder writes: > > > When `git ls-remote` is run outside a repo with some promisor remote > > related config options that make it write to its config, namely: > > > > - "promisor.acceptFromServerUrl", which makes it auto-create a > > remote, or > > - "promisor.acceptFromServer" with "promisor.storeFields", which > > makes it store fields, > > > > it crashes in configure_auto_promisor_remote() or store_one_field(), as > > the `repo` argument passed to these functions has its `gitdir` member > > set to NULL. > > It is tricky that "ls-remote" wants to work outside a repository. > > > This has been happening since 3e20258d11 (promisor-remote: allow a > > client to store fields, 2026-02-16) for the `storeFields` case, and > > since 7a56394fc6 (promisor-remote: auto-configure unknown remotes, > > 2026-05-27) for the auto-creation case. > > > > Let's fix that by checking if `repo->gitdir` is NULL at the beginning > > of filter_promisor_remote() and returning from it right away in that > > case. It doesn't make sense to further process the promisor remote > > advertisement as `git ls-remote` currently has no use for promisor > > remotes anyway. > > Another possibility is to nip this higher in the callchain. If we > know, as you said, "ls-remote" has no need to talk about promisors, > turning promisor_remote_reply() into a NOOP outside a repository > might be better, but the function does not take a repository > parameter to be able to tell if we have a repository in the first > place---perhaps we should add one? An illustration patch below. > The callers (there are only two) should of course be updated. I was wondering myself whether a better fix would be to start passing down the repository and then detect this case by checking for `!repo` instead. From my point of view it's nowadays a bit of a code smell to check whether the passed repository itself is actually an initialized one or not: if we aren't operating inside a repository, then the caller shouldn't pass one. That may be a bigger refactoring though, so depending on its scope I'm happy to live with the easier fix for now. > diff --git c/promisor-remote.c w/promisor-remote.c > index 316d9950aa..702c53c2c4 100644 > --- c/promisor-remote.c > +++ w/promisor-remote.c > @@ -1373,11 +1373,20 @@ static void filter_promisor_remote(struct repository *repo, > } > } > > -void promisor_remote_reply(const char *info, char **accepted_out) > +void promisor_remote_reply(struct repository *repo, const char *info, char **accepted_out) > { > struct string_list accepted_remotes = STRING_LIST_INIT_NODUP; > > - filter_promisor_remote(the_repository, &accepted_remotes, info); > + /* > + * "ls-remote" has no business talking about promisors, and worse yet, > + * it can be run outside a repository. > + */ > + if (!repo->gitdir) { > + if (accepted_out) > + *accepted_out = NULL; > + return; > + } But in any case, we should also detect the case where `!repo`, I'd say. Otherwise we'll have to adapt this code again once this funciton's call chains get rid of `the_repository`. Thanks! Patrick