mv test: recreate mod/ directory instead of relying on stale copy

The tests for 'git mv moves a submodule' functionality often run commands like git mv sub mod/sub to move a submodule into a subdirectory. Just like plain /bin/mv, this is supposed to succeed if the mod/ parent directory exists and fail if it doesn't exist. Usually these tests mkdir the parent directory beforehand, but some instead rely on it being left behind by previous tests. More precisely, when 'git reset --hard' tries to move to a state where mod/sub is not present any more, it would perform the following operations: rmdir("mod/sub") rmdir("mod") The first fails with ENOENT because the test script removed mod/sub with "rm -rf" already, so 'reset --hard' doesn't bother to move on to the second, and the mod/ directory is kept around. Better to explicitly remove and re-create the mod/ directory so later tests don't have to depend on the directory left behind by the earlier ones at all (making it easier to rearrange or skip some tests in the file or to tweak 'reset --hard' behavior without breaking unrelated tests). Noticed while testing a patch that fixes the reset --hard behavior described above. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Sep 10, 2014 at 14:01 UTC 2b2b1e4d27b4e44c0c46d4857c76b8391d303af3
1 file changed +10 -5
t/t7001-mv.sh
+10 -5
@@ -350,10 +350,11 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
350 '
351
352 test_expect_success 'git mv moves a submodule with gitfile' '
353 - rm -rf mod/sub &&
353 + rm -rf mod &&
354 git reset --hard &&
355 git submodule update &&
356 entry="$(git ls-files --stage sub | cut -f 1)" &&
357 + mkdir mod &&
358 (
359 cd mod &&
360 git mv ../sub/ .
@@ -372,11 +373,12 @@ test_expect_success 'git mv moves a submodule with gitfile' '
373 '
374
375 test_expect_success 'mv does not complain when no .gitmodules file is found' '
375 - rm -rf mod/sub &&
376 + rm -rf mod &&
377 git reset --hard &&
378 git submodule update &&
379 git rm .gitmodules &&
380 entry="$(git ls-files --stage sub | cut -f 1)" &&
381 + mkdir mod &&
382 git mv sub mod/sub 2>actual.err &&
383 ! test -s actual.err &&
384 ! test -e sub &&
@@ -390,11 +392,12 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' '
392 '
393
394 test_expect_success 'mv will error out on a modified .gitmodules file unless staged' '
393 - rm -rf mod/sub &&
395 + rm -rf mod &&
396 git reset --hard &&
397 git submodule update &&
398 git config -f .gitmodules foo.bar true &&
399 entry="$(git ls-files --stage sub | cut -f 1)" &&
400 + mkdir mod &&
401 test_must_fail git mv sub mod/sub 2>actual.err &&
402 test -s actual.err &&
403 test -e sub &&
@@ -413,13 +416,14 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta
416 '
417
418 test_expect_success 'mv issues a warning when section is not found in .gitmodules' '
416 - rm -rf mod/sub &&
419 + rm -rf mod &&
420 git reset --hard &&
421 git submodule update &&
422 git config -f .gitmodules --remove-section submodule.sub &&
423 git add .gitmodules &&
424 entry="$(git ls-files --stage sub | cut -f 1)" &&
425 echo "warning: Could not find section in .gitmodules where path=sub" >expect.err &&
426 + mkdir mod &&
427 git mv sub mod/sub 2>actual.err &&
428 test_i18ncmp expect.err actual.err &&
429 ! test -e sub &&
@@ -433,9 +437,10 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule
437 '
438
439 test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
436 - rm -rf mod/sub &&
440 + rm -rf mod &&
441 git reset --hard &&
442 git submodule update &&
443 + mkdir mod &&
444 git mv -n sub mod/sub 2>actual.err &&
445 test -f sub/.git &&
446 git diff-index --exit-code HEAD &&