tests: remove leftover untracked files

Remove untracked files that are unwanted after they are done being used. While the set of cases in this patch is certainly far from comprehensive, it was motivated by some work to see what the fallout would be if we were to make the removal of untracked files as a side effect of other commands into an error. Some cases were a bit more involved than the testcase changes included in this patch, but the ones included here represent the simple cases. While this patch is not that important since we are not changing the behavior of those other commands into an error in the near term, I thought these changes were useful anyway as an explicit documentation of the intent that these untracked files are no longer useful. Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Acked-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Sep 11, 2021 at 17:08 UTC f222bd34ffde9e2fb06794bb657fd9dc371261df
12 files changed +18 -4
t/t0090-cache-tree.sh
+1
@@ -195,6 +195,7 @@ test_expect_success 'reset --hard gives cache-tree' '
195
196 test_expect_success 'reset --hard without index gives cache-tree' '
197 rm -f .git/index &&
198 + git clean -fd &&
199 git reset --hard &&
200 test_cache_tree
201 '
t/t2021-checkout-overwrite.sh
+1
@@ -48,6 +48,7 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' '
48
49 test_expect_success SYMLINKS 'the symlink remained' '
50
51 + test_when_finished "rm a/b" &&
52 test -h a/b
53 '
54
t/t3404-rebase-interactive.sh
+1
@@ -297,6 +297,7 @@ test_expect_success 'abort with error when new base cannot be checked out' '
297 output &&
298 test_i18ngrep "file1" output &&
299 test_path_is_missing .git/rebase-merge &&
300 + rm file1 &&
301 git reset --hard HEAD^
302 '
303
t/t3435-rebase-gpg-sign.sh
+1
@@ -65,6 +65,7 @@ test_rebase_gpg_sign ! true -i --gpg-sign --no-gpg-sign
65 test_rebase_gpg_sign false -i --no-gpg-sign --gpg-sign
66
67 test_expect_failure 'rebase -p --no-gpg-sign override commit.gpgsign' '
68 + test_when_finished "git clean -f" &&
69 git reset --hard merged &&
70 git config commit.gpgsign true &&
71 git rebase -p --no-gpg-sign --onto=one fork-point main &&
t/t3510-cherry-pick-sequence.sh
+1
@@ -238,6 +238,7 @@ test_expect_success 'allow skipping commit but not abort for a new history' '
238 '
239
240 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
241 + test_when_finished "rm unrelated" &&
242 pristine_detach initial &&
243 git rm --cached unrelated &&
244 git commit -m "untrack unrelated" &&
t/t5304-prune.sh
+1
@@ -291,6 +291,7 @@ test_expect_success 'prune: handle HEAD reflog in multiple worktrees' '
291 cat ../expected >blob &&
292 git add blob &&
293 git commit -m "second commit in third" &&
294 + git clean -f && # Remove untracked left behind by deleting index
295 git reset --hard HEAD^
296 ) &&
297 git prune --expire=now &&
t/t6415-merge-dir-to-symlink.sh
+4 -2
@@ -25,7 +25,8 @@ test_expect_success 'checkout does not clobber untracked symlink' '
25 git reset --hard main &&
26 git rm --cached a/b &&
27 git commit -m "untracked symlink remains" &&
28 - test_must_fail git checkout start^0
28 + test_must_fail git checkout start^0 &&
29 + git clean -fd # Do not leave the untracked symlink in the way
30 '
31
32 test_expect_success 'a/b-2/c/d is kept when clobbering symlink b' '
@@ -34,7 +35,8 @@ test_expect_success 'a/b-2/c/d is kept when clobbering symlink b' '
35 git rm --cached a/b &&
36 git commit -m "untracked symlink remains" &&
37 git checkout -f start^0 &&
37 - test_path_is_file a/b-2/c/d
38 + test_path_is_file a/b-2/c/d &&
39 + git clean -fd # Do not leave the untracked symlink in the way
40 '
41
42 test_expect_success 'checkout should not have deleted a/b-2/c/d' '
t/t6424-merge-unrelated-index-changes.sh
+1
@@ -132,6 +132,7 @@ test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
132
133 # Make index match B
134 git diff C B -- | git apply --cached &&
135 + test_when_finished "git clean -fd" && # Do not leave untracked around
136 # Merge B & F, with B as "head"
137 git merge-recursive A -- B F > out &&
138 test_i18ngrep "Already up to date" out
t/t6430-merge-recursive.sh
+3 -1
@@ -718,7 +718,9 @@ test_expect_success 'merge-recursive remembers the names of all base trees' '
718 # merge-recursive prints in reverse order, but we do not care
719 sort <trees >expect &&
720 sed -n "s/^virtual //p" out | sort >actual &&
721 - test_cmp expect actual
721 + test_cmp expect actual &&
722 +
723 + git clean -fd
724 '
725
726 test_expect_success 'merge-recursive internal merge resolves to the sameness' '
t/t6436-merge-overwrite.sh
+2 -1
@@ -68,7 +68,8 @@ test_expect_success 'will not overwrite removed file' '
68 git commit -m "rm c1.c" &&
69 cp important c1.c &&
70 test_must_fail git merge c1a &&
71 - test_cmp important c1.c
71 + test_cmp important c1.c &&
72 + rm c1.c # Do not leave untracked file in way of future tests
73 '
74
75 test_expect_success 'will not overwrite re-added file' '
t/t7201-co.sh
+1
@@ -585,6 +585,7 @@ test_expect_success 'checkout --conflict=diff3' '
585 '
586
587 test_expect_success 'failing checkout -b should not break working tree' '
588 + git clean -fd && # Remove untracked files in the way
589 git reset --hard main &&
590 git symbolic-ref HEAD refs/heads/main &&
591 test_must_fail git checkout -b renamer side^ &&
t/t7600-merge.sh
+1
@@ -717,6 +717,7 @@ test_expect_success 'failed fast-forward merge with --autostash' '
717 git reset --hard c0 &&
718 git merge-file file file.orig file.5 &&
719 cp file.5 other &&
720 + test_when_finished "rm other" &&
721 test_must_fail git merge --autostash c1 2>err &&
722 test_i18ngrep "Applied autostash." err &&
723 test_cmp file.5 file