submodule tests: add tests for top-level flag output
Exhaustively test for how combining various "mixed-level" "git submodule" option works. "Mixed-level" here means options that are accepted by a mixture of the top-level "submodule" command, and e.g. the "status" sub-command. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Ævar Arnfjörð Bjarmason committed
Nov 8, 2022 at 15:10 UTC
44874cbd19afb6ee6fa7dad01dbe6eec161cc94b
2 files changed
+179
t/t7400-submodule-basic.sh
+10
@@ -579,6 +579,16 @@ test_expect_success 'status should be "modified" after submodule commit' '
579
grep "^+$rev2" list
580
'
581
582
+test_expect_success '"submodule --cached" command forms should be identical' '
583
+ git submodule status --cached >expect &&
584
+
585
+ git submodule --cached >actual &&
586
+ test_cmp expect actual &&
587
+
588
+ git submodule --cached status >actual &&
589
+ test_cmp expect actual
590
+'
591
+
592
test_expect_success 'the --cached sha1 should be rev1' '
593
git submodule --cached status >list &&
594
grep "^+$rev1" list
t/t7422-submodule-output.sh
new
+169
@@ -0,0 +1,169 @@
1
+#!/bin/sh
2
+
3
+test_description='submodule --cached, --quiet etc. output'
4
+
5
+. ./test-lib.sh
6
+. "$TEST_DIRECTORY"/lib-t3100.sh
7
+
8
+setup_sub () {
9
+ local d="$1" &&
10
+ shift &&
11
+ git $@ clone . "$d" &&
12
+ git $@ submodule add ./"$d"
13
+}
14
+
15
+normalize_status () {
16
+ sed -e 's/-g[0-9a-f]*/-gHASH/'
17
+}
18
+
19
+test_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
+
65
+for opts in "" "status"
66
+do
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
+ '
79
+done
80
+
81
+for opts in \
82
+ "status --recursive"
83
+do
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
+ '
101
+done
102
+
103
+for opts in \
104
+ "--quiet" \
105
+ "--quiet status" \
106
+ "status --quiet"
107
+do
108
+ test_expect_success "git submodule $opts" '
109
+ git submodule $opts >out &&
110
+ test_must_be_empty out
111
+ '
112
+done
113
+
114
+for opts in \
115
+ "--cached" \
116
+ "--cached status" \
117
+ "status --cached"
118
+do
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
+ '
131
+done
132
+
133
+for opts in \
134
+ "--cached --quiet" \
135
+ "--cached --quiet status" \
136
+ "--cached status --quiet" \
137
+ "--quiet status --cached" \
138
+ "status --cached --quiet"
139
+do
140
+ test_expect_success "git submodule $opts" '
141
+ git submodule $opts >out &&
142
+ test_must_be_empty out
143
+ '
144
+done
145
+
146
+for opts in \
147
+ "status --cached --recursive" \
148
+ "--cached status --recursive"
149
+do
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
+ '
167
+done
168
+
169
+test_done