Git fork
1#!/bin/sh
2
3test_description='submodule --cached, --quiet etc. output'
4
5. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-t3100.sh
7
8setup_sub () {
9 local d="$1" &&
10 shift &&
11 git $@ clone . "$d" &&
12 git $@ submodule add ./"$d"
13}
14
15normalize_status () {
16 sed -e 's/-g[0-9a-f]*/-gHASH/'
17}
18
19test_expect_success 'setup' '
20 test_commit A &&
21 test_commit B &&
22 setup_sub S &&
23 setup_sub S.D &&
24 setup_sub S.C &&
25 setup_sub S.C.D &&
26 setup_sub X &&
27 git add S* &&
28 test_commit C &&
29
30 # recursive in X/
31 git -C X pull &&
32 GIT_ALLOW_PROTOCOL=file git -C X submodule update --init &&
33
34 # dirty
35 for d in S.D X/S.D
36 do
37 echo dirty >"$d"/A.t || return 1
38 done &&
39
40 # commit (for --cached)
41 for d in S.C* X/S.C*
42 do
43 git -C "$d" reset --hard A || return 1
44 done &&
45
46 # dirty
47 for d in S*.D X/S*.D
48 do
49 echo dirty >"$d/C2.t" || return 1
50 done &&
51
52 for ref in A B C
53 do
54 # Not different with SHA-1 and SHA-256, just (ab)using
55 # test_oid_cache as a variable bag to avoid using
56 # $(git rev-parse ...).
57 oid=$(git rev-parse $ref) &&
58 test_oid_cache <<-EOF || return 1
59 $ref sha1:$oid
60 $ref sha256:$oid
61 EOF
62 done
63'
64
65for opts in "" "status"
66do
67 test_expect_success "git submodule $opts" '
68 sed -e "s/^>//" >expect <<-EOF &&
69 > $(test_oid B) S (B)
70 >+$(test_oid A) S.C (A)
71 >+$(test_oid A) S.C.D (A)
72 > $(test_oid B) S.D (B)
73 >+$(test_oid C) X (C)
74 EOF
75 git submodule $opts >actual.raw &&
76 normalize_status <actual.raw >actual &&
77 test_cmp expect actual
78 '
79done
80
81for opts in \
82 "status --recursive"
83do
84 test_expect_success "git submodule $opts" '
85 sed -e "s/^>//" >expect <<-EOF &&
86 > $(test_oid B) S (B)
87 >+$(test_oid A) S.C (A)
88 >+$(test_oid A) S.C.D (A)
89 > $(test_oid B) S.D (B)
90 >+$(test_oid C) X (C)
91 > $(test_oid B) X/S (B)
92 >+$(test_oid A) X/S.C (A)
93 >+$(test_oid A) X/S.C.D (A)
94 > $(test_oid B) X/S.D (B)
95 > $(test_oid B) X/X (B)
96 EOF
97 git submodule $opts >actual.raw &&
98 normalize_status <actual.raw >actual &&
99 test_cmp expect actual
100 '
101done
102
103for opts in \
104 "--quiet" \
105 "--quiet status" \
106 "status --quiet"
107do
108 test_expect_success "git submodule $opts" '
109 git submodule $opts >out &&
110 test_must_be_empty out
111 '
112done
113
114for opts in \
115 "--cached" \
116 "--cached status" \
117 "status --cached"
118do
119 test_expect_success "git submodule $opts" '
120 sed -e "s/^>//" >expect <<-EOF &&
121 > $(test_oid B) S (B)
122 >+$(test_oid B) S.C (B)
123 >+$(test_oid B) S.C.D (B)
124 > $(test_oid B) S.D (B)
125 >+$(test_oid B) X (B)
126 EOF
127 git submodule $opts >actual.raw &&
128 normalize_status <actual.raw >actual &&
129 test_cmp expect actual
130 '
131done
132
133for opts in \
134 "--cached --quiet" \
135 "--cached --quiet status" \
136 "--cached status --quiet" \
137 "--quiet status --cached" \
138 "status --cached --quiet"
139do
140 test_expect_success "git submodule $opts" '
141 git submodule $opts >out &&
142 test_must_be_empty out
143 '
144done
145
146for opts in \
147 "status --cached --recursive" \
148 "--cached status --recursive"
149do
150 test_expect_success "git submodule $opts" '
151 sed -e "s/^>//" >expect <<-EOF &&
152 > $(test_oid B) S (B)
153 >+$(test_oid B) S.C (B)
154 >+$(test_oid B) S.C.D (B)
155 > $(test_oid B) S.D (B)
156 >+$(test_oid B) X (B)
157 > $(test_oid B) X/S (B)
158 >+$(test_oid B) X/S.C (B)
159 >+$(test_oid B) X/S.C.D (B)
160 > $(test_oid B) X/S.D (B)
161 > $(test_oid B) X/X (B)
162 EOF
163 git submodule $opts >actual.raw &&
164 normalize_status <actual.raw >actual &&
165 test_cmp expect actual
166 '
167done
168
169test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE' '
170 # The test setup is somewhat involved because triggering a SIGPIPE is
171 # racy with buffered pipes. To avoid the raciness we thus need to make
172 # sure that the subprocess in question fills the buffers completely,
173 # which requires a couple thousand submodules in total.
174 test_when_finished "rm -rf submodule repo" &&
175 git init submodule &&
176 (
177 cd submodule &&
178 test_commit initial &&
179
180 COMMIT=$(git rev-parse HEAD) &&
181 for i in $(test_seq 2000)
182 do
183 echo "[submodule \"sm-$i\"]" &&
184 echo "path = recursive-submodule-path-$i" ||
185 return 1
186 done >gitmodules &&
187 BLOB=$(git hash-object -w --stdin <gitmodules) &&
188
189 printf "100644 blob $BLOB\t.gitmodules\n" >tree &&
190 test_seq -f "160000 commit $COMMIT\trecursive-submodule-path-%d" 2000 >>tree &&
191 TREE=$(git mktree <tree) &&
192
193 COMMIT=$(git commit-tree "$TREE") &&
194 git reset --hard "$COMMIT"
195 ) &&
196
197 git init repo &&
198 (
199 cd repo &&
200 GIT_ALLOW_PROTOCOL=file git submodule add "$(pwd)"/../submodule &&
201 { git submodule status --recursive 2>err; echo $?>status; } |
202 grep -q recursive-submodule-path-1 &&
203 test_must_be_empty err &&
204 test_match_signal 13 "$(cat status)"
205 )
206'
207
208test_done