On Fri, Mar 8, 2019 at 4:59 AM Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote: > diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh > @@ -0,0 +1,87 @@ > +test_expect_success 'switch to a commit' ' > + test_must_fail git switch master^{commit} > +' The title of this test was a bit misleading for me; I would have found it easier to understand what's being tested had it said "switch without --detach" or something. > +test_expect_success 'switch and detach' ' > + test_when_finished git switch master && > + git switch --detach master^{commit} && > + test_must_fail git symbolic-ref HEAD > +' In fact, if the two tests were combined, it would have been even clearer (for me): test_expect_success 'switch and detach' ' test_when_finished git switch master && test_must_fail git switch master^{commit} && git switch --detach master^{commit} && test_must_fail git symbolic-ref HEAD ' Not worth a re-roll. > +test_expect_success 'switch and create branch' ' > + test_when_finished git switch master && > + git switch -c temp master^ && > + test_cmp_rev master^ refs/heads/temp && > + echo refs/heads/temp >expected-branch && > + git symbolic-ref HEAD >actual-branch && > + test_cmp expected-branch actual-branch > +' > + > +test_expect_success 'force create branch from HEAD' ' > + test_when_finished git switch master && > + git switch --detach master && > + git switch -C temp && > + test_cmp_rev master refs/heads/temp && > + echo refs/heads/temp >expected-branch && > + git symbolic-ref HEAD >actual-branch && > + test_cmp expected-branch actual-branch > +' Maybe also demonstrate that -C is actually needed here by leading in with a failing -c: ... git switch --detach master && test_must_fail git switch -c temp && git switch -C temp && ... Not worth a re-roll. > +test_expect_success 'guess and create branch ' ' > + test_when_finished git switch master && > + test_must_fail git switch foo && > + git switch --guess foo && > + echo refs/heads/foo >expected && > + git symbolic-ref HEAD >actual && > + test_cmp expected actual > +' The above suggestions about --detach/-C reflect how you did it in this test, in which you first try "git switch foo" without the --guess option, expecting it to fail, and then repeat with the option, expecting it to succeed.