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 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 'resolve_ref(master)' '
51 SHA1=`git -C sub rev-parse master` &&
52 echo "$SHA1 refs/heads/master 0x0" >expected &&
53 $RUN resolve-ref refs/heads/master 0 >actual &&
54 test_cmp expected actual
55'
56
57test_expect_success 'verify_ref(new-master)' '
58 $RUN verify-ref refs/heads/new-master
59'
60
61test_expect_success 'for_each_reflog()' '
62 $RUN for-each-reflog | sort | cut -c 42- >actual &&
63 cat >expected <<-\EOF &&
64 HEAD 0x1
65 refs/heads/master 0x0
66 refs/heads/new-master 0x0
67 EOF
68 test_cmp expected actual
69'
70
71test_expect_success 'for_each_reflog_ent()' '
72 $RUN for-each-reflog-ent HEAD >actual && cat actual &&
73 head -n1 actual | grep first &&
74 tail -n2 actual | head -n1 | grep master.to.new
75'
76
77test_expect_success 'for_each_reflog_ent_reverse()' '
78 $RUN for-each-reflog-ent-reverse HEAD >actual &&
79 head -n1 actual | grep master.to.new &&
80 tail -n2 actual | head -n1 | grep first
81'
82
83test_expect_success 'reflog_exists(HEAD)' '
84 $RUN reflog-exists HEAD
85'
86
87test_expect_success 'delete_reflog() not allowed' '
88 test_must_fail $RUN delete-reflog HEAD
89'
90
91test_expect_success 'create-reflog() not allowed' '
92 test_must_fail $RUN create-reflog HEAD 1
93'
94
95test_done