Subject: Re: [PATCH] read_gitfile_gently(): return non-repo path on error

From: Patrick Steinhardt <[email-masked]>
Date: Thu, 4 Jun 2026 09:08:48 +0200

On Thu, Jun 04, 2026 at 02:27:20AM -0400, Jeff King wrote:
> On Tue, Jun 02, 2026 at 10:36:34AM +0200, Patrick Steinhardt wrote:
> 
> > > The correct output (which this patch produces) is:
> > > 
> > >   fatal: not a git repository: /home/peff/compile/git/.git/worktrees/worktree3
> > > 
> > > And indeed, that path is missing. But why? I feel like I've run into
> > > this same problem occasionally over the last year or so, but never
> > > before. Did we get more aggressive about removing worktrees at some
> > > point? I haven't been able to reproduce whatever is killing off the
> > > worktree directory, and by the time I see the error it is long gone.
> > 
> > Both git-gc(1) and git-maintenance(1) prune orphaned worktrees that are
> > older than three months by default, which can be configured via
> > "gc.worktreePruneExpire". That logic has changed in 4dda60c9df (Merge
> > branch 'ps/maintenance-missing-tasks', 2025-05-15), which would kind of
> > match your timeline.
> > 
> > But rereading that patch series I cannot really see how it could result
> > in more aggressive pruning of worktrees. We used `git worktree prune
> > --expire <expiry>` before that series, and we still use that logic now.
> 
> Yeah, but this .git/worktrees/ directory shouldn't be pruned _at all_.
> The worktree itself is still there (which is why I'm getting the error).
> So perhaps there's a bug in checking that things are still there, or
> perhaps something is corrupting .git/worktrees/*/gitdir.

Oh, that sounds somewhat scary.

> Another option is "I moved my git checkout and the worktree prune
> couldn't find the directory as an absolute path", but I'm sure I didn't
> do that.
> 
> An even more exotic option is that I run Git's test suite a lot, and
> very occasionally bugs in the test suite cause the script to escape the
> trash directory. And some scripts do run "rm -r .git/worktrees". I find
> it pretty unlikely for that to be the culprit though.
> 
> Oh well. I don't have any good leads, so I guess I'll see if it happens
> again. But maybe now if somebody else sees it we can commiserate. :)

I'll certainly be on the watchout.

Patrick