On 11/5/21 04:53, Jeff King wrote:
+ wt->is_current ? + _("can't fetch in current branch") : + _("branch checked out in worktree"),
Sure, I’ll go ahead and add this. We can make further improvements here if we proceed with removing the other error path, which seems to have enough complications that we should consider it after merging this bug fix.
Hmm. That is the same check that is on the fetch side, isn't it? In a bare repository, we will not do any of these current-branch checks. What is weird in your example is that you are adding a worktree to a bare repository. Is that a supported workflow? Should that make it non-bare? I notice that there is a worktree->is_bare flag, and that find_shared_symref() would not report such a bare entry to us. But I'm really unclear how any of that is supposed to work (how do you have a bare worktree, and what does it mean?).
worktree->is_bare is only ever potentially set for the main working tree (.git/..). Although a bare repository doesn’t have a main working tree, it can still have other working trees created with git worktree. Making a temporary working tree can be useful to quickly inspect or change a bare repository. It’s also useful for sharing refs, remotes, and object storage between several working trees where any of them might be created or deleted, and there isn’t one that should be considered primary.
The Zulip installer works this way to save some disk space and re-cloning time while allowing for simple rollbacks to a previous deployment directory (https://github.com/zulip/zulip/pull/18487), which is how my team stumbled on the issue.
I think that's all orthogonal to the main purpose of your patch here. You may want to post about it separately with a different subject to get the attention of folks who work on worktrees.
I expect this subject line will have already caught the attention of those folks, but I’ll add a patch 2/2 with a more specific subject line for this issue.
Anders