git hook run: add an --ignore-missing flag
[alt-git.git] / t / t1405-main-ref-store.sh
blob1a3ee8845d67e92190261e33d93c98f540972f7f
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-lib.sh
10 RUN="test-tool ref-store main"
13 test_expect_success 'setup' '
14 test_commit one
17 test_expect_success REFFILES 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
18 N=`find .git/refs -type f | wc -l` &&
19 test "$N" != 0 &&
20 $RUN pack-refs PACK_REFS_PRUNE,PACK_REFS_ALL &&
21 N=`find .git/refs -type f` &&
22 test -z "$N"
25 test_expect_success 'create_symref(FOO, refs/heads/main)' '
26 $RUN create-symref FOO refs/heads/main nothing &&
27 echo refs/heads/main >expected &&
28 git symbolic-ref FOO >actual &&
29 test_cmp expected actual
32 test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
33 git tag -a -m new-tag new-tag HEAD &&
34 git rev-parse FOO -- &&
35 git rev-parse refs/tags/new-tag -- &&
36 m=$(git rev-parse main) &&
37 $RUN delete-refs REF_NO_DEREF nothing FOO refs/tags/new-tag &&
38 test_must_fail git rev-parse --symbolic-full-name FOO &&
39 test_must_fail git rev-parse FOO -- &&
40 test_must_fail git rev-parse refs/tags/new-tag --
43 test_expect_success 'rename_refs(main, new-main)' '
44 git rev-parse main >expected &&
45 $RUN rename-ref refs/heads/main refs/heads/new-main &&
46 git rev-parse new-main >actual &&
47 test_cmp expected actual &&
48 test_commit recreate-main
51 test_expect_success 'for_each_ref(refs/heads/)' '
52 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
53 cat >expected <<-\EOF &&
54 main 0x0
55 new-main 0x0
56 EOF
57 test_cmp expected actual
60 test_expect_success 'for_each_ref() is sorted' '
61 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
62 sort actual > expected &&
63 test_cmp expected actual
66 test_expect_success 'resolve_ref(new-main)' '
67 SHA1=`git rev-parse new-main` &&
68 echo "$SHA1 refs/heads/new-main 0x0" >expected &&
69 $RUN resolve-ref refs/heads/new-main 0 >actual &&
70 test_cmp expected actual
73 test_expect_success 'verify_ref(new-main)' '
74 $RUN verify-ref refs/heads/new-main
77 test_expect_success 'for_each_reflog()' '
78 $RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
79 cat >expected <<-\EOF &&
80 HEAD 0x1
81 refs/heads/main 0x0
82 refs/heads/new-main 0x0
83 EOF
84 test_cmp expected actual
87 test_expect_success 'for_each_reflog_ent()' '
88 $RUN for-each-reflog-ent HEAD >actual &&
89 head -n1 actual | grep one &&
90 tail -n1 actual | grep recreate-main
93 test_expect_success 'for_each_reflog_ent_reverse()' '
94 $RUN for-each-reflog-ent-reverse HEAD >actual &&
95 head -n1 actual | grep recreate-main &&
96 tail -n1 actual | grep one
99 test_expect_success 'reflog_exists(HEAD)' '
100 $RUN reflog-exists HEAD
103 test_expect_success 'delete_reflog(HEAD)' '
104 $RUN delete-reflog HEAD &&
105 test_must_fail git reflog exists HEAD
108 test_expect_success 'create-reflog(HEAD)' '
109 $RUN create-reflog HEAD &&
110 git reflog exists HEAD
113 test_expect_success 'delete_ref(refs/heads/foo)' '
114 git checkout -b foo &&
115 FOO_SHA1=`git rev-parse foo` &&
116 git checkout --detach &&
117 test_commit bar-commit &&
118 git checkout -b bar &&
119 BAR_SHA1=`git rev-parse bar` &&
120 $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
121 echo $BAR_SHA1 >expected &&
122 git rev-parse refs/heads/foo >actual &&
123 test_cmp expected actual
126 test_expect_success 'delete_ref(refs/heads/foo)' '
127 SHA1=`git rev-parse foo` &&
128 git checkout --detach &&
129 $RUN delete-ref msg refs/heads/foo $SHA1 0 &&
130 test_must_fail git rev-parse refs/heads/foo --
133 test_done