completion: fix incorrect bash/zsh string equality check
[git/debian.git] / t / t1405-main-ref-store.sh
bloba237d9880ead84fac4e36c1a34082452d06f0fff
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"
12 test_expect_success 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
13 test_commit one &&
14 N=`find .git/refs -type f | wc -l` &&
15 test "$N" != 0 &&
16 $RUN pack-refs 3 &&
17 N=`find .git/refs -type f | wc -l`
20 test_expect_success 'create_symref(FOO, refs/heads/main)' '
21 $RUN create-symref FOO refs/heads/main nothing &&
22 echo refs/heads/main >expected &&
23 git symbolic-ref FOO >actual &&
24 test_cmp expected actual
27 test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
28 git tag -a -m new-tag new-tag HEAD &&
29 git rev-parse FOO -- &&
30 git rev-parse refs/tags/new-tag -- &&
31 m=$(git rev-parse main) &&
32 REF_NO_DEREF=1 &&
33 $RUN delete-refs $REF_NO_DEREF nothing FOO refs/tags/new-tag &&
34 test_must_fail git rev-parse --symbolic-full-name FOO &&
35 test_must_fail git rev-parse FOO -- &&
36 test_must_fail git rev-parse refs/tags/new-tag --
39 test_expect_success 'rename_refs(main, new-main)' '
40 git rev-parse main >expected &&
41 $RUN rename-ref refs/heads/main refs/heads/new-main &&
42 git rev-parse new-main >actual &&
43 test_cmp expected actual &&
44 test_commit recreate-main
47 test_expect_success 'for_each_ref(refs/heads/)' '
48 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
49 cat >expected <<-\EOF &&
50 main 0x0
51 new-main 0x0
52 EOF
53 test_cmp expected actual
56 test_expect_success 'for_each_ref() is sorted' '
57 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
58 sort actual > expected &&
59 test_cmp expected actual
62 test_expect_success 'resolve_ref(new-main)' '
63 SHA1=`git rev-parse new-main` &&
64 echo "$SHA1 refs/heads/new-main 0x0" >expected &&
65 $RUN resolve-ref refs/heads/new-main 0 >actual &&
66 test_cmp expected actual
69 test_expect_success 'verify_ref(new-main)' '
70 $RUN verify-ref refs/heads/new-main
73 test_expect_success 'for_each_reflog()' '
74 $RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
75 cat >expected <<-\EOF &&
76 HEAD 0x1
77 refs/heads/main 0x0
78 refs/heads/new-main 0x0
79 EOF
80 test_cmp expected actual
83 test_expect_success 'for_each_reflog_ent()' '
84 $RUN for-each-reflog-ent HEAD >actual &&
85 head -n1 actual | grep one &&
86 tail -n2 actual | head -n1 | grep recreate-main
89 test_expect_success 'for_each_reflog_ent_reverse()' '
90 $RUN for-each-reflog-ent-reverse HEAD >actual &&
91 head -n1 actual | grep recreate-main &&
92 tail -n2 actual | head -n1 | grep one
95 test_expect_success 'reflog_exists(HEAD)' '
96 $RUN reflog-exists HEAD
99 test_expect_success 'delete_reflog(HEAD)' '
100 $RUN delete-reflog HEAD &&
101 ! test -f .git/logs/HEAD
104 test_expect_success 'create-reflog(HEAD)' '
105 $RUN create-reflog HEAD 1 &&
106 test -f .git/logs/HEAD
109 test_expect_success 'delete_ref(refs/heads/foo)' '
110 git checkout -b foo &&
111 FOO_SHA1=`git rev-parse foo` &&
112 git checkout --detach &&
113 test_commit bar-commit &&
114 git checkout -b bar &&
115 BAR_SHA1=`git rev-parse bar` &&
116 $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
117 echo $BAR_SHA1 >expected &&
118 git rev-parse refs/heads/foo >actual &&
119 test_cmp expected actual
122 test_expect_success 'delete_ref(refs/heads/foo)' '
123 SHA1=`git rev-parse foo` &&
124 git checkout --detach &&
125 $RUN delete-ref msg refs/heads/foo $SHA1 0 &&
126 test_must_fail git rev-parse refs/heads/foo --
129 test_done