Re: [PATCH 2/2] for-each-repo: work correctly in a worktree
- From
Jeff King <peff@peff.net>
- Date
- Feb 25, 2026, 13:23 UTC
- Message-ID
- <20260225132326.GB2139176@coredump.intra.peff.net>
- In-Reply-To
- <fce7662f-d741-41e1-93dd-f82e65e04f41@gmail.com>
On Tue, Feb 24, 2026 at 07:11:13AM -0500, Derrick Stolee wrote:
Show 6 quoted lines
> > it is passed, before calling sub-programs. That's a bigger change, but > > possibly it could or should be flagging an error for some cases? I > > dunno. > I'm surprised that passing '-C <repo>' doesn't already overwrite these > variables but I suppose environment variables override arguments in this > case. (This is the root of the bug.)
I can see why you'd be surprised if you think of "-C" as "change to this git repo". But it really is "change to this directory". It is perfectly OK to "git -C" into a non-toplevel directory of a repo (and continue respecting any repo discovery that happened already and is in the environment), or even weird stuff like:
GIT_DIR=/some/repo.git git -C /some/worktree add foo
What you almost kind-of want is "--git-dir", except it puts the onus on the caller to find the actual repo directory (so detecting bare vs discovering the .git). Part of the point of introducing -C long ago was because --git-dir was so annoying to use.
Probably there is room for some middle-ground option, which is "do repo detection starting in this directory and use that as the --git-dir" (and I guess also do worktree discovery in the same way). But I don't think we would ever switch -C to that. It would almost certainly break lots of people if we changed it now.
-Peff