]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: remove leftover untracked files
authorElijah Newren <newren@gmail.com>
Sat, 11 Sep 2021 17:08:42 +0000 (17:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 12 Sep 2021 23:42:40 +0000 (16:42 -0700)
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>
12 files changed:
t/t0090-cache-tree.sh
t/t2021-checkout-overwrite.sh
t/t3404-rebase-interactive.sh
t/t3435-rebase-gpg-sign.sh
t/t3510-cherry-pick-sequence.sh
t/t5304-prune.sh
t/t6415-merge-dir-to-symlink.sh
t/t6424-merge-unrelated-index-changes.sh
t/t6430-merge-recursive.sh
t/t6436-merge-overwrite.sh
t/t7201-co.sh
t/t7600-merge.sh

index 9bf66c9e68dd7b99434dfeaa19a0cc8a7618f039..906757264844b67b0c72914b3aa2a6d02e17101c 100755 (executable)
@@ -195,6 +195,7 @@ test_expect_success 'reset --hard gives cache-tree' '
 
 test_expect_success 'reset --hard without index gives cache-tree' '
        rm -f .git/index &&
+       git clean -fd &&
        git reset --hard &&
        test_cache_tree
 '
index 70d69263e6821514ada6ace0ba7846360585f32d..660132ff8d5919b1af69010ff4122b1f18d6a742 100755 (executable)
@@ -48,6 +48,7 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' '
 
 test_expect_success SYMLINKS 'the symlink remained' '
 
+       test_when_finished "rm a/b" &&
        test -h a/b
 '
 
index d877872e8f4ad15f3af4ad8e2bf22948fae34a6c..972ce026bbcc55bb2a0b04abe89d0b2e35120f5c 100755 (executable)
@@ -297,6 +297,7 @@ test_expect_success 'abort with error when new base cannot be checked out' '
                output &&
        test_i18ngrep "file1" output &&
        test_path_is_missing .git/rebase-merge &&
+       rm file1 &&
        git reset --hard HEAD^
 '
 
index ec1076685802221f4ba89c75aa09b1283c48e2a9..5f8ba2c7399dc3d1cb5661097a3a3f0990624e77 100755 (executable)
@@ -65,6 +65,7 @@ test_rebase_gpg_sign ! true  -i --gpg-sign --no-gpg-sign
 test_rebase_gpg_sign   false -i --no-gpg-sign --gpg-sign
 
 test_expect_failure 'rebase -p --no-gpg-sign override commit.gpgsign' '
+       test_when_finished "git clean -f" &&
        git reset --hard merged &&
        git config commit.gpgsign true &&
        git rebase -p --no-gpg-sign --onto=one fork-point main &&
index 49010aa9469d9dc48637e80fae79248a8cf826fb..3b0fa66c33da5857012b56d465c5ffad77f61be4 100755 (executable)
@@ -238,6 +238,7 @@ test_expect_success 'allow skipping commit but not abort for a new history' '
 '
 
 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
+       test_when_finished "rm unrelated" &&
        pristine_detach initial &&
        git rm --cached unrelated &&
        git commit -m "untrack unrelated" &&
index 7cabb85ca6e128add7c86bc9940e6a7c66c3886c..8ae314af585482ec240fed353613faf6b23ebb67 100755 (executable)
@@ -291,6 +291,7 @@ test_expect_success 'prune: handle HEAD reflog in multiple worktrees' '
                cat ../expected >blob &&
                git add blob &&
                git commit -m "second commit in third" &&
+               git clean -f && # Remove untracked left behind by deleting index
                git reset --hard HEAD^
        ) &&
        git prune --expire=now &&
index 2ce104aca7cc2923aa88d191efec2894d12eb86e..2655e295f5ae4536eaf86dcf95e8062f61cc2948 100755 (executable)
@@ -25,7 +25,8 @@ test_expect_success 'checkout does not clobber untracked symlink' '
        git reset --hard main &&
        git rm --cached a/b &&
        git commit -m "untracked symlink remains" &&
-       test_must_fail git checkout start^0
+       test_must_fail git checkout start^0 &&
+       git clean -fd    # Do not leave the untracked symlink in the way
 '
 
 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' '
        git rm --cached a/b &&
        git commit -m "untracked symlink remains" &&
        git checkout -f start^0 &&
-       test_path_is_file a/b-2/c/d
+       test_path_is_file a/b-2/c/d &&
+       git clean -fd    # Do not leave the untracked symlink in the way
 '
 
 test_expect_success 'checkout should not have deleted a/b-2/c/d' '
index 5e3779ebc9310bfb25d0c6579f234ecf4fabd12e..89dd544f3880c46b4207220427da86e1580c5789 100755 (executable)
@@ -132,6 +132,7 @@ test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
 
        # Make index match B
        git diff C B -- | git apply --cached &&
+       test_when_finished "git clean -fd" &&  # Do not leave untracked around
        # Merge B & F, with B as "head"
        git merge-recursive A -- B F > out &&
        test_i18ngrep "Already up to date" out
index ffcc01fe65d017caa3fad22968a7fd6d35dd4a37..a0efe7cb6dbe77215f0b2bd220f6974ad0c17ec0 100755 (executable)
@@ -718,7 +718,9 @@ test_expect_success 'merge-recursive remembers the names of all base trees' '
        # merge-recursive prints in reverse order, but we do not care
        sort <trees >expect &&
        sed -n "s/^virtual //p" out | sort >actual &&
-       test_cmp expect actual
+       test_cmp expect actual &&
+
+       git clean -fd
 '
 
 test_expect_success 'merge-recursive internal merge resolves to the sameness' '
index 84b4aacf496d1df73c6adf83860db430bc1c1c4c..c0b7bd7c3fe55303d62caed5f4c02368d2e3fd3c 100755 (executable)
@@ -68,7 +68,8 @@ test_expect_success 'will not overwrite removed file' '
        git commit -m "rm c1.c" &&
        cp important c1.c &&
        test_must_fail git merge c1a &&
-       test_cmp important c1.c
+       test_cmp important c1.c &&
+       rm c1.c  # Do not leave untracked file in way of future tests
 '
 
 test_expect_success 'will not overwrite re-added file' '
index 7f6e23a4bb98afe1725b54f7e312f48b80c773b7..b7ba1c3268e32935ca62f0e3f562a80c99f84481 100755 (executable)
@@ -585,6 +585,7 @@ test_expect_success 'checkout --conflict=diff3' '
 '
 
 test_expect_success 'failing checkout -b should not break working tree' '
+       git clean -fd &&  # Remove untracked files in the way
        git reset --hard main &&
        git symbolic-ref HEAD refs/heads/main &&
        test_must_fail git checkout -b renamer side^ &&
index 2ef39d3088e80690781e43c671ab1de11beed55f..c773e30b3fa17bc129ca78afe3aef9194d77cb1d 100755 (executable)
@@ -717,6 +717,7 @@ test_expect_success 'failed fast-forward merge with --autostash' '
        git reset --hard c0 &&
        git merge-file file file.orig file.5 &&
        cp file.5 other &&
+       test_when_finished "rm other" &&
        test_must_fail git merge --autostash c1 2>err &&
        test_i18ngrep "Applied autostash." err &&
        test_cmp file.5 file