@matheusbsbs / matheus-bagliano / commits / a76c944bbe
Fork 0

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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Apr 10, 2010 at 00:39 UTC a76c944bbe207953c9f0f23311702d2b8225d486
1 file changed +88 -15
t/t7400-submodule-basic.sh
+88 -15
@@ -49,63 +49,136 @@ test_expect_success 'setup - add an example entry to .gitmodules' '
49 git config submodule.example.url git://example.com/init.git
50 '
51
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 +
68 (
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"
75 )
59 -'
76 +}
77
78 test_expect_success 'submodule add' '
79 + echo "refs/heads/master" >expect &&
80 + >empty &&
81 +
82 (
83 cd addtest &&
84 git submodule add "$submodurl" submod &&
85 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
93 '
94
95 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 +
103 (
104 cd addtest &&
105 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
114 '
115
116 test_expect_success 'submodule add with ./ in path' '
117 + echo "refs/heads/master" >expect &&
118 + >empty &&
119 +
120 (
121 cd addtest &&
122 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
123 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
131 '
132
133 test_expect_success 'submodule add with // in path' '
134 + echo "refs/heads/master" >expect &&
135 + >empty &&
136 +
137 (
138 cd addtest &&
139 git submodule add "$submodurl" slashslashsubmod///frotz// &&
140 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
148 '
149
150 test_expect_success 'submodule add with /.. in path' '
151 + echo "refs/heads/master" >expect &&
152 + >empty &&
153 +
154 (
155 cd addtest &&
156 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
157 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
165 '
166
167 test_expect_success 'submodule add with ./, /.. and // in path' '
168 + echo "refs/heads/master" >expect &&
169 + >empty &&
170 +
171 (
172 cd addtest &&
173 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
174 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
182 '
183
184 test_expect_success 'status should fail for unmapped paths' '