Skip to content

Commit a76c944

Browse files
jrngitster
authored andcommitted
t7400: clarify 'submodule add' tests
A new reader may not realize what properties the $submodurl repository needs to have. One of the tests is checking that ‘submodule add -b foo’ creates a ‘foo’ branch. Put this test in context by checking that without -b, no ‘foo’ branch is created. While at it, make sure each added submodule is a reasonable repository, with clean index, no stray files, and so on. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe454b1 commit a76c944

File tree

1 file changed

+88
-15
lines changed

1 file changed

+88
-15
lines changed

t/t7400-submodule-basic.sh

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,63 +49,136 @@ test_expect_success 'setup - add an example entry to .gitmodules' '
4949
git config submodule.example.url git://example.com/init.git
5050
'
5151

52-
test_expect_success 'Prepare submodule add testing' '
53-
submodurl=$(pwd)
52+
test_expect_success 'setup - repository to add submodules to' '
53+
git init addtest
54+
'
55+
56+
# The 'submodule add' tests need some repository to add as a submodule.
57+
# The trash directory is a good one as any.
58+
submodurl=$TRASH_DIRECTORY
59+
60+
listbranches() {
61+
git for-each-ref --format='%(refname)' 'refs/heads/*'
62+
}
63+
64+
inspect() {
65+
dir=$1 &&
66+
dotdot="${2:-..}" &&
67+
5468
(
55-
mkdir addtest &&
56-
cd addtest &&
57-
git init
69+
cd "$dir" &&
70+
listbranches >"$dotdot/heads" &&
71+
{ git symbolic-ref HEAD || :; } >"$dotdot/head" &&
72+
git update-index --refresh &&
73+
git diff-files --exit-code &&
74+
git clean -n -d -x >"$dotdot/untracked"
5875
)
59-
'
76+
}
6077

6178
test_expect_success 'submodule add' '
79+
echo "refs/heads/master" >expect &&
80+
>empty &&
81+
6282
(
6383
cd addtest &&
6484
git submodule add "$submodurl" submod &&
6585
git submodule init
66-
)
86+
) &&
87+
88+
rm -f heads head untracked &&
89+
inspect addtest/submod ../.. &&
90+
test_cmp expect heads &&
91+
test_cmp expect head &&
92+
test_cmp empty untracked
6793
'
6894

6995
test_expect_success 'submodule add --branch' '
96+
echo "refs/heads/initial" >expect-head &&
97+
cat <<-\EOF >expect-heads &&
98+
refs/heads/initial
99+
refs/heads/master
100+
EOF
101+
>empty &&
102+
70103
(
71104
cd addtest &&
72105
git submodule add -b initial "$submodurl" submod-branch &&
73-
git submodule init &&
74-
cd submod-branch &&
75-
git branch | grep initial
76-
)
106+
git submodule init
107+
) &&
108+
109+
rm -f heads head untracked &&
110+
inspect addtest/submod-branch ../.. &&
111+
test_cmp expect-heads heads &&
112+
test_cmp expect-head head &&
113+
test_cmp empty untracked
77114
'
78115

79116
test_expect_success 'submodule add with ./ in path' '
117+
echo "refs/heads/master" >expect &&
118+
>empty &&
119+
80120
(
81121
cd addtest &&
82122
git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
83123
git submodule init
84-
)
124+
) &&
125+
126+
rm -f heads head untracked &&
127+
inspect addtest/dotsubmod/frotz ../../.. &&
128+
test_cmp expect heads &&
129+
test_cmp expect head &&
130+
test_cmp empty untracked
85131
'
86132

87133
test_expect_success 'submodule add with // in path' '
134+
echo "refs/heads/master" >expect &&
135+
>empty &&
136+
88137
(
89138
cd addtest &&
90139
git submodule add "$submodurl" slashslashsubmod///frotz// &&
91140
git submodule init
92-
)
141+
) &&
142+
143+
rm -f heads head untracked &&
144+
inspect addtest/slashslashsubmod/frotz ../../.. &&
145+
test_cmp expect heads &&
146+
test_cmp expect head &&
147+
test_cmp empty untracked
93148
'
94149

95150
test_expect_success 'submodule add with /.. in path' '
151+
echo "refs/heads/master" >expect &&
152+
>empty &&
153+
96154
(
97155
cd addtest &&
98156
git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
99157
git submodule init
100-
)
158+
) &&
159+
160+
rm -f heads head untracked &&
161+
inspect addtest/realsubmod ../.. &&
162+
test_cmp expect heads &&
163+
test_cmp expect head &&
164+
test_cmp empty untracked
101165
'
102166

103167
test_expect_success 'submodule add with ./, /.. and // in path' '
168+
echo "refs/heads/master" >expect &&
169+
>empty &&
170+
104171
(
105172
cd addtest &&
106173
git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
107174
git submodule init
108-
)
175+
) &&
176+
177+
rm -f heads head untracked &&
178+
inspect addtest/realsubmod2 ../.. &&
179+
test_cmp expect heads &&
180+
test_cmp expect head &&
181+
test_cmp empty untracked
109182
'
110183

111184
test_expect_success 'status should fail for unmapped paths' '

0 commit comments

Comments
 (0)