On 14-feb-2023 23:17:42, Eric Sunshine wrote: > > +test_expect_success 'switch back when temporarily detached and checked out elsewhere ' ' > > + test_when_finished " > > + git worktree remove wt1 && > > + git worktree remove wt2 && > > + git branch -d shared > > + git checkout - > > + " && > > + git checkout -b shared && > > The test_when_finished() call has an odd mix of &&-chain and missing &&-chain. Oops, thanks, that was unintentional and hides an error ... > > If you do use &&-chaining inside test_when_finished(), you have to be > careful that _none_ of the cleanup commands fail, otherwise > test_when_finished() itself will fail, making the entire test fail, > _even if_ the test body succeeded. So, &&-chaining the commands in > this test_when_finished() is undesirable since any of the `git > worktree remove` and `git branch -d` commands could potentially fail. > Better would be to drop the &&-chain and ensure that the final command > succeeds. > > It may be a good idea to use `||:` at the end of each command as > documentation for readers that any of the cleanup commands might fail, > which could happen if something in the body of the test fails. > > The `git branch -d shared` cleanup command fails unconditionally > because it's still the checked-out branch in the directory. You need > to swap the `git branch -d shared` and `git checkout -` commands. ... in fact, that needs to be "git branch -D shared" to successfully delete that unmerged branch. Considering also, what you pointed out, swapping the two commands. About the `||:`, maybe it's a good idea to keep the '&&' and let the test fail if any command fails in the cleanup. However, if that is also part of the test, maybe must not be in the cleanup... so I don't have a strong opinion on that. I'll wait some time, if there is no argument against the change, I'll reroll with the fix and using '||:' as you suggested. Thank you for your review and comments.