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