t9814: guarantee only one source exists in git-p4 copy tests

By using a tree with multiple identical files and allowing copy detection to choose any one of them, the check in the test is unnecessarily complex. We can simplify by: * Modify source file (file2) before copying the file. * Check that only file2 is the source in the output of "p4 filelog". * Remove all "case" statements and replace them with simple tests to check that source is "file2". Signed-off-by: Vitor Antunes <vitor.hda@gmail.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vitor Antunes committed Apr 6, 2015 at 00:08 UTC f1f4c84dccba24d606e82d3436c1c4f573712d28
1 file changed +31 -15
t/t9814-git-p4-rename.sh
+31 -15
@@ -132,6 +132,9 @@ test_expect_success 'detect copies' '
132 cd "$git" &&
133 git config git-p4.skipSubmitEdit true &&
134
135 + echo "file8" >>file2 &&
136 + git commit -a -m "Differentiate file2" &&
137 + git p4 submit &&
138 cp file2 file8 &&
139 git add file8 &&
140 git commit -a -m "Copy file2 to file8" &&
@@ -140,6 +143,10 @@ test_expect_success 'detect copies' '
143 p4 filelog //depot/file8 &&
144 p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
145
146 + echo "file9" >>file2 &&
147 + git commit -a -m "Differentiate file2" &&
148 + git p4 submit &&
149 +
150 cp file2 file9 &&
151 git add file9 &&
152 git commit -a -m "Copy file2 to file9" &&
@@ -149,28 +156,39 @@ test_expect_success 'detect copies' '
156 p4 filelog //depot/file9 &&
157 p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
158
159 + echo "file10" >>file2 &&
160 + git commit -a -m "Differentiate file2" &&
161 + git p4 submit &&
162 +
163 echo "file2" >>file2 &&
164 cp file2 file10 &&
165 git add file2 file10 &&
166 git commit -a -m "Modify and copy file2 to file10" &&
167 git diff-tree -r -C HEAD &&
168 + src=$(git diff-tree -r -C HEAD | sed 1d | sed 2d | cut -f2) &&
169 + test "$src" = file2 &&
170 git p4 submit &&
171 p4 filelog //depot/file10 &&
159 - p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
172 + p4 filelog //depot/file10 | grep -q "branch from //depot/file2" &&
173 +
174 + echo "file11" >>file2 &&
175 + git commit -a -m "Differentiate file2" &&
176 + git p4 submit &&
177
178 cp file2 file11 &&
179 git add file11 &&
180 git commit -a -m "Copy file2 to file11" &&
181 git diff-tree -r -C --find-copies-harder HEAD &&
182 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
166 - case "$src" in
167 - file2 | file10) : ;; # happy
168 - *) false ;; # not
169 - esac &&
183 + test "$src" = file2 &&
184 git config git-p4.detectCopiesHarder true &&
185 git p4 submit &&
186 p4 filelog //depot/file11 &&
173 - p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
187 + p4 filelog //depot/file11 | grep -q "branch from //depot/file2" &&
188 +
189 + echo "file12" >>file2 &&
190 + git commit -a -m "Differentiate file2" &&
191 + git p4 submit &&
192
193 cp file2 file12 &&
194 echo "some text" >>file12 &&
@@ -180,15 +198,16 @@ test_expect_success 'detect copies' '
198 level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
199 test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
200 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
183 - case "$src" in
184 - file10 | file11) : ;; # happy
185 - *) false ;; # not
186 - esac &&
201 + test "$src" = file2 &&
202 git config git-p4.detectCopies $(($level + 2)) &&
203 git p4 submit &&
204 p4 filelog //depot/file12 &&
205 p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
206
207 + echo "file13" >>file2 &&
208 + git commit -a -m "Differentiate file2" &&
209 + git p4 submit &&
210 +
211 cp file2 file13 &&
212 echo "different text" >>file13 &&
213 git add file13 &&
@@ -197,14 +216,11 @@ test_expect_success 'detect copies' '
216 level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
217 test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
218 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
200 - case "$src" in
201 - file10 | file11 | file12) : ;; # happy
202 - *) false ;; # not
203 - esac &&
219 + test "$src" = file2 &&
220 git config git-p4.detectCopies $(($level - 2)) &&
221 git p4 submit &&
222 p4 filelog //depot/file13 &&
207 - p4 filelog //depot/file13 | grep -q "branch from //depot/file"
223 + p4 filelog //depot/file13 | grep -q "branch from //depot/file2"
224 )
225 '
226