The eleventh batch
[git/gitster.git] / t / t1405-main-ref-store.sh
bloba6bcd62ab658eefcd11ae1778692ad6d7f4c3008
1 #!/bin/sh
3 test_description='test main ref store api'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 RUN="test-tool ref-store main"
14 test_expect_success 'setup' '
15 test_commit one
18 test_expect_success 'create_symref(FOO, refs/heads/main)' '
19 $RUN create-symref FOO refs/heads/main nothing &&
20 echo refs/heads/main >expected &&
21 git symbolic-ref FOO >actual &&
22 test_cmp expected actual
25 test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
26 git tag -a -m new-tag new-tag HEAD &&
27 git rev-parse FOO -- &&
28 git rev-parse refs/tags/new-tag -- &&
29 m=$(git rev-parse main) &&
30 $RUN delete-refs REF_NO_DEREF nothing FOO refs/tags/new-tag &&
31 test_must_fail git rev-parse --symbolic-full-name FOO &&
32 test_must_fail git rev-parse FOO -- &&
33 test_must_fail git rev-parse refs/tags/new-tag --
36 test_expect_success 'rename_refs(main, new-main)' '
37 git rev-parse main >expected &&
38 $RUN rename-ref refs/heads/main refs/heads/new-main &&
39 git rev-parse new-main >actual &&
40 test_cmp expected actual &&
41 test_commit recreate-main
44 test_expect_success 'for_each_ref(refs/heads/)' '
45 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
46 cat >expected <<-\EOF &&
47 main 0x0
48 new-main 0x0
49 EOF
50 test_cmp expected actual
53 test_expect_success 'for_each_ref() is sorted' '
54 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
55 sort actual > expected &&
56 test_cmp expected actual
59 test_expect_success 'resolve_ref(new-main)' '
60 SHA1=`git rev-parse new-main` &&
61 echo "$SHA1 refs/heads/new-main 0x0" >expected &&
62 $RUN resolve-ref refs/heads/new-main 0 >actual &&
63 test_cmp expected actual
66 test_expect_success 'verify_ref(new-main)' '
67 $RUN verify-ref refs/heads/new-main
70 test_expect_success 'for_each_reflog()' '
71 $RUN for-each-reflog >actual &&
72 cat >expected <<-\EOF &&
73 HEAD
74 refs/heads/main
75 refs/heads/new-main
76 EOF
77 test_cmp expected actual
80 test_expect_success 'for_each_reflog_ent()' '
81 $RUN for-each-reflog-ent HEAD >actual &&
82 head -n1 actual | grep one &&
83 tail -n1 actual | grep recreate-main
86 test_expect_success 'for_each_reflog_ent_reverse()' '
87 $RUN for-each-reflog-ent-reverse HEAD >actual &&
88 head -n1 actual | grep recreate-main &&
89 tail -n1 actual | grep one
92 test_expect_success 'reflog_exists(HEAD)' '
93 $RUN reflog-exists HEAD
96 test_expect_success 'delete_reflog(HEAD)' '
97 $RUN delete-reflog HEAD &&
98 test_must_fail git reflog exists HEAD
101 test_expect_success 'create-reflog(HEAD)' '
102 $RUN create-reflog HEAD &&
103 git reflog exists HEAD
106 test_expect_success 'delete_ref(refs/heads/foo)' '
107 git checkout -b foo &&
108 FOO_SHA1=`git rev-parse foo` &&
109 git checkout --detach &&
110 test_commit bar-commit &&
111 git checkout -b bar &&
112 BAR_SHA1=`git rev-parse bar` &&
113 $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
114 echo $BAR_SHA1 >expected &&
115 git rev-parse refs/heads/foo >actual &&
116 test_cmp expected actual
119 test_expect_success 'delete_ref(refs/heads/foo)' '
120 SHA1=`git rev-parse foo` &&
121 git checkout --detach &&
122 $RUN delete-ref msg refs/heads/foo $SHA1 0 &&
123 test_must_fail git rev-parse refs/heads/foo --
126 test_done