api-parse-options.txt: document OPT_CMDMODE()
[git/debian.git] / t / t1401-symbolic-ref.sh
blob64968b789161bb5b88be59a80348a29924d26208
1 #!/bin/sh
3 test_description='basic symbolic-ref tests'
4 . ./test-lib.sh
6 # If the tests munging HEAD fail, they can break detection of
7 # the git repo, meaning that further tests will operate on
8 # the surrounding git repo instead of the trash directory.
9 reset_to_sane() {
10 echo ref: refs/heads/foo >.git/HEAD
13 test_expect_success 'symbolic-ref writes HEAD' '
14 git symbolic-ref HEAD refs/heads/foo &&
15 echo ref: refs/heads/foo >expect &&
16 test_cmp expect .git/HEAD
19 test_expect_success 'symbolic-ref reads HEAD' '
20 echo refs/heads/foo >expect &&
21 git symbolic-ref HEAD >actual &&
22 test_cmp expect actual
25 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
26 test_must_fail git symbolic-ref HEAD foo
28 reset_to_sane
30 test_expect_success 'symbolic-ref refuses bare sha1' '
31 echo content >file && git add file && git commit -m one &&
32 test_must_fail git symbolic-ref HEAD `git rev-parse HEAD`
34 reset_to_sane
36 test_expect_success 'symbolic-ref deletes HEAD' '
37 git symbolic-ref -d HEAD &&
38 test_path_is_file .git/refs/heads/foo &&
39 test_path_is_missing .git/HEAD
41 reset_to_sane
43 test_expect_success 'symbolic-ref deletes dangling HEAD' '
44 git symbolic-ref HEAD refs/heads/missing &&
45 git symbolic-ref -d HEAD &&
46 test_path_is_missing .git/refs/heads/missing &&
47 test_path_is_missing .git/HEAD
49 reset_to_sane
51 test_expect_success 'symbolic-ref fails to delete missing FOO' '
52 echo "fatal: Cannot delete FOO, not a symbolic ref" >expect &&
53 test_must_fail git symbolic-ref -d FOO >actual 2>&1 &&
54 test_cmp expect actual
56 reset_to_sane
58 test_expect_success 'symbolic-ref fails to delete real ref' '
59 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect &&
60 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 &&
61 test_path_is_file .git/refs/heads/foo &&
62 test_cmp expect actual
64 reset_to_sane
66 test_expect_success 'symbolic-ref reports failure in exit code' '
67 test_when_finished "rm -f .git/HEAD.lock" &&
68 >.git/HEAD.lock &&
69 test_must_fail git symbolic-ref HEAD refs/heads/whatever
72 test_expect_success 'symbolic-ref writes reflog entry' '
73 git checkout -b log1 &&
74 test_commit one &&
75 git checkout -b log2 &&
76 test_commit two &&
77 git checkout --orphan orphan &&
78 git symbolic-ref -m create HEAD refs/heads/log1 &&
79 git symbolic-ref -m update HEAD refs/heads/log2 &&
80 cat >expect <<-\EOF &&
81 update
82 create
83 EOF
84 git log --format=%gs -g >actual &&
85 test_cmp expect actual
88 test_done