]>
Commit | Line | Data |
---|---|---|
2269e2a8 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='test submodule ref store api' | |
4 | ||
06d53148 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
9081a421 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
2269e2a8 NTND |
9 | . ./test-lib.sh |
10 | ||
65370d81 | 11 | RUN="test-tool ref-store submodule:sub" |
2269e2a8 NTND |
12 | |
13 | test_expect_success 'setup' ' | |
14 | git init sub && | |
15 | ( | |
16 | cd sub && | |
17 | test_commit first && | |
973e20b8 | 18 | git checkout -b new-main && |
36a31792 | 19 | git tag -a -m new-tag new-tag HEAD |
2269e2a8 NTND |
20 | ) |
21 | ' | |
22 | ||
23 | test_expect_success 'pack_refs() not allowed' ' | |
24 | test_must_fail $RUN pack-refs 3 | |
25 | ' | |
26 | ||
2269e2a8 | 27 | test_expect_success 'create_symref() not allowed' ' |
06d53148 | 28 | test_must_fail $RUN create-symref FOO refs/heads/main nothing |
2269e2a8 NTND |
29 | ' |
30 | ||
31 | test_expect_success 'delete_refs() not allowed' ' | |
64da4199 | 32 | test_must_fail $RUN delete-refs 0 nothing FOO refs/tags/new-tag |
2269e2a8 NTND |
33 | ' |
34 | ||
35 | test_expect_success 'rename_refs() not allowed' ' | |
06d53148 | 36 | test_must_fail $RUN rename-ref refs/heads/main refs/heads/new-main |
2269e2a8 NTND |
37 | ' |
38 | ||
39 | test_expect_success 'for_each_ref(refs/heads/)' ' | |
b1484ca9 | 40 | $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual && |
2269e2a8 | 41 | cat >expected <<-\EOF && |
06d53148 JS |
42 | main 0x0 |
43 | new-main 0x0 | |
2269e2a8 NTND |
44 | EOF |
45 | test_cmp expected actual | |
46 | ' | |
47 | ||
adac8115 | 48 | test_expect_success 'for_each_ref() is sorted' ' |
b1484ca9 | 49 | $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual && |
adac8115 NTND |
50 | sort actual > expected && |
51 | test_cmp expected actual | |
52 | ' | |
53 | ||
06d53148 JS |
54 | test_expect_success 'resolve_ref(main)' ' |
55 | SHA1=`git -C sub rev-parse main` && | |
56 | echo "$SHA1 refs/heads/main 0x0" >expected && | |
57 | $RUN resolve-ref refs/heads/main 0 >actual && | |
2269e2a8 NTND |
58 | test_cmp expected actual |
59 | ' | |
60 | ||
06d53148 JS |
61 | test_expect_success 'verify_ref(new-main)' ' |
62 | $RUN verify-ref refs/heads/new-main | |
2269e2a8 NTND |
63 | ' |
64 | ||
65 | test_expect_success 'for_each_reflog()' ' | |
b1484ca9 | 66 | $RUN for-each-reflog | sort | cut -d" " -f 2- >actual && |
2269e2a8 NTND |
67 | cat >expected <<-\EOF && |
68 | HEAD 0x1 | |
06d53148 JS |
69 | refs/heads/main 0x0 |
70 | refs/heads/new-main 0x0 | |
2269e2a8 NTND |
71 | EOF |
72 | test_cmp expected actual | |
73 | ' | |
74 | ||
75 | test_expect_success 'for_each_reflog_ent()' ' | |
3c29e21e | 76 | $RUN for-each-reflog-ent HEAD >actual && |
2269e2a8 | 77 | head -n1 actual | grep first && |
21f0e850 | 78 | tail -n1 actual | grep main.to.new |
2269e2a8 NTND |
79 | ' |
80 | ||
81 | test_expect_success 'for_each_reflog_ent_reverse()' ' | |
82 | $RUN for-each-reflog-ent-reverse HEAD >actual && | |
06d53148 | 83 | head -n1 actual | grep main.to.new && |
21f0e850 | 84 | tail -n1 actual | grep first |
2269e2a8 NTND |
85 | ' |
86 | ||
87 | test_expect_success 'reflog_exists(HEAD)' ' | |
88 | $RUN reflog-exists HEAD | |
89 | ' | |
90 | ||
91 | test_expect_success 'delete_reflog() not allowed' ' | |
92 | test_must_fail $RUN delete-reflog HEAD | |
93 | ' | |
94 | ||
95 | test_expect_success 'create-reflog() not allowed' ' | |
7b089120 | 96 | test_must_fail $RUN create-reflog HEAD |
2269e2a8 NTND |
97 | ' |
98 | ||
99 | test_done |