On 17-ene-2023 15:27:29, Junio C Hamano wrote: > being solved. Rather, it is unclear what problem you are solving. Sorry, I didn't explain the motivation well in the message. First, I'm not sure if "ignore_current_worktree" is correct, maybe needs to be "prefer_current_worktree". Having said that, let me use an example. With... $ git worktree add wt1 -b main $ git worktree add wt2 -f main ... we get confuse results: $ git -C wt1 rebase main main Current branch main is up to date. $ git -C wt2 rebase main main fatal: 'main' is already checked out... The problem I'm trying to solve is that find_shared_symref() returns the first matching worktree, and a possible matching "current worktree" might not be the first matching one. That's why die_if_checked_out() dies with "git -C wt2". find_shared_symref() searches through the list of worktrees that get_worktrees() composes: first the main worktree and then, as getdir() returns them, those in .git/worktrees/*. The search is sequential and once a match is found, it is returned. And so die_if_checked_out(), when asked to "ignore_current_worktree", is going to consider for "is_current" the worktree which may or may not be the "current" one, depending on the sequence from get_worktree(), and getdir() ultimately. If we want to disallow operations on a worktree with a checked out branch also on another worktree, we need the "ignore_current_worktree". But, and now I'm more in favor of this, if we prefer to allow the operation, we need a "prefer_current_worktree", to induce find_shared_symref() to return the "current" one if it matches, or any other one that matches.