checkout: implement "-" abbreviation, add docs and tests
[git/ljr.git] / t / t2012-checkout-last.sh
blob320f6eb2be6c1e3ee0a0fbf4b7e478b626415387
1 #!/bin/sh
3 test_description='checkout can switch to last branch'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 echo hello >world &&
9 git add world &&
10 git commit -m initial &&
11 git branch other &&
12 echo "hello again" >>world &&
13 git add world &&
14 git commit -m second
17 test_expect_success '"checkout -" does not work initially' '
18 test_must_fail git checkout -
21 test_expect_success 'first branch switch' '
22 git checkout other
25 test_expect_success '"checkout -" switches back' '
26 git checkout - &&
27 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
30 test_expect_success '"checkout -" switches forth' '
31 git checkout - &&
32 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
35 test_expect_success 'detach HEAD' '
36 git checkout $(git rev-parse HEAD)
39 test_expect_success '"checkout -" attaches again' '
40 git checkout - &&
41 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
44 test_expect_success '"checkout -" detaches again' '
45 git checkout - &&
46 test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
47 test_must_fail git symbolic-ref HEAD
50 test_done