mbox series

[v4,0/4] fix die_if_checked_out() when ignore_current_worktree

Message ID 6fed3b1b-1c4e-9298-19b6-7ad9c04c87dd@gmail.com (mailing list archive)
Headers show
Series fix die_if_checked_out() when ignore_current_worktree | expand

Message

Rubén Justo Feb. 25, 2023, 2:14 p.m. UTC
Since v3, two errors in 4/4 have been fixed:
  - "checkout -" must be done before "branch -d"
  - "branch -D" instead of "branch -d" because "shared" is a non-merged
    branch.

Also, '||:' has been used to chain commands in the test_when_finished()
block.

Rubén Justo (4):
  worktree: introduce is_shared_symref()
  branch: fix die_if_checked_out() when ignore_current_worktree
  rebase: refuse to switch to a branch already checked out elsewhere (test)
  switch: reject if the branch is already checked out elsewhere (test)

 branch.c          | 14 +++++++----
 t/t2060-switch.sh | 29 ++++++++++++++++++++++
 t/t3400-rebase.sh | 14 +++++++++++
 worktree.c        | 63 +++++++++++++++++++++++------------------------
 worktree.h        |  6 +++++
 5 files changed, 89 insertions(+), 37 deletions(-)

Range-diff against v3:
1:  40b5ea54d3 = 1:  22d0944aad worktree: introduce is_shared_symref()
2:  2f1479b354 = 2:  e7ba7b6fdd branch: fix die_if_checked_out() when ignore_current_worktree
3:  81a5b619c3 = 3:  8de8319d0e rebase: refuse to switch to a branch already checked out elsewhere (test)
4:  6559e58344 ! 4:  27d6ae2755 switch: reject if the branch is already checked out elsewhere (test)
    @@ t/t2060-switch.sh: test_expect_success 'tracking info copied with autoSetupMerge
      
     +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 worktree remove wt1 ||:
    ++		git worktree remove wt2 ||:
    ++		git checkout - ||:
    ++		git branch -D shared ||:
     +	" &&
     +	git checkout -b shared &&
     +	test_commit shared-first &&

Comments

Junio C Hamano Feb. 25, 2023, 10:50 p.m. UTC | #1
Rubén Justo <rjusto@gmail.com> writes:

>      +	test_when_finished "
>     -+		git worktree remove wt1 &&
>     -+		git worktree remove wt2 &&
>     -+		git branch -d shared
>     -+		git checkout -
>     ++		git worktree remove wt1 ||:
>     ++		git worktree remove wt2 ||:
>     ++		git checkout - ||:
>     ++		git branch -D shared ||:
>      +	" &&

Sorry, but I do not get the point of this construct.  The
test_cleanup variable that accumulates test_when_finished scripts is
evaled without -e shopt set, so you can just remove all these ||:
and add a single "true" at the end, like

	...
	git checkout -
	git branch -D shared
	:
    " &&

for exactly the same effect, no?
Rubén Justo Feb. 27, 2023, midnight UTC | #2
On 25-feb-2023 14:50:07, Junio C Hamano wrote:
> Rubén Justo <rjusto@gmail.com> writes:
> 
> >      +	test_when_finished "
> >     -+		git worktree remove wt1 &&
> >     -+		git worktree remove wt2 &&
> >     -+		git branch -d shared
> >     -+		git checkout -
> >     ++		git worktree remove wt1 ||:
> >     ++		git worktree remove wt2 ||:
> >     ++		git checkout - ||:
> >     ++		git branch -D shared ||:
> >      +	" &&
> 
> Sorry, but I do not get the point of this construct.  The
> test_cleanup variable that accumulates test_when_finished scripts is
> evaled without -e shopt set, so you can just remove all these ||:
> and add a single "true" at the end, like
> 
> 	...
> 	git checkout -
> 	git branch -D shared
> 	:
>     " &&
> 
> for exactly the same effect, no?

Yes, of course.

I agree that all of that '||:' can be confusing, but I'm not sure if a
final ':' is much better.

As I said in my response to Eric, I don't have a clear opinion here.

test_when_finished() was introduced in 2bf78867 (test-lib: Let tests
specify commands to be run at end of test, 2010-05-02) to allow
indicating some actions to be executed after the test block finishes,
even if the test fails, to leave a repository or overall situation
healthy for the next tests.

With that in mind, I ask myself, is it worth removing the worktrees
here?  Is it worth reporting a possible error in that removal?  If, for
example, in the future we deny the removal of a worktree under bisect,
is it worth reporting the failure here?  What about the "shared"
branch? ...

I Dunno.

Thank you for reviewing this patch.