diff options
author | Denton Liu <liu.denton@gmail.com> | 2021-02-08 23:28:49 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-02-11 13:34:58 -0800 |
commit | bbaa45c3aace10e25ae9dd966e867796fbf440ad (patch) | |
tree | 32bef3e0e417aa24487c837d61c9ea8e702c4cc3 | |
parent | t3905: remove spaces after redirect operators (diff) | |
download | tgif-bbaa45c3aace10e25ae9dd966e867796fbf440ad.tar.xz |
t3905: move all commands into test cases
In order to modernize the tests, move commands that currently run
outside of test cases into a test case. Where possible, clean up files
that are produced using test_when_finished() but in the case where files
persist over multiple test cases, create a new test case to perform
cleanup.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | t/t3905-stash-include-untracked.sh | 147 |
1 files changed, 75 insertions, 72 deletions
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh index 1d416944b7..892a2c8057 100755 --- a/t/t3905-stash-include-untracked.sh +++ b/t/t3905-stash-include-untracked.sh @@ -25,48 +25,48 @@ test_expect_success 'stash save --include-untracked some dirty working directory git diff-index --cached --quiet HEAD ' -cat >expect <<EOF -?? actual -?? expect -EOF - test_expect_success 'stash save --include-untracked cleaned the untracked files' ' + cat >expect <<-EOF && + ?? actual + ?? expect + EOF + git status --porcelain >actual && test_cmp expect actual ' -tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) -untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) -cat >expect.diff <<EOF -diff --git a/HEAD b/HEAD -new file mode 100644 -index 0000000..$tracked ---- /dev/null -+++ b/HEAD -@@ -0,0 +1 @@ -+1 -diff --git a/file2 b/file2 -new file mode 100644 -index 0000000..$tracked ---- /dev/null -+++ b/file2 -@@ -0,0 +1 @@ -+1 -diff --git a/untracked/untracked b/untracked/untracked -new file mode 100644 -index 0000000..$untracked ---- /dev/null -+++ b/untracked/untracked -@@ -0,0 +1 @@ -+untracked -EOF -cat >expect.lstree <<EOF -HEAD -file2 -untracked -EOF - test_expect_success 'stash save --include-untracked stashed the untracked files' ' + tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) && + untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) && + cat >expect.diff <<-EOF && + diff --git a/HEAD b/HEAD + new file mode 100644 + index 0000000..$tracked + --- /dev/null + +++ b/HEAD + @@ -0,0 +1 @@ + +1 + diff --git a/file2 b/file2 + new file mode 100644 + index 0000000..$tracked + --- /dev/null + +++ b/file2 + @@ -0,0 +1 @@ + +1 + diff --git a/untracked/untracked b/untracked/untracked + new file mode 100644 + index 0000000..$untracked + --- /dev/null + +++ b/untracked/untracked + @@ -0,0 +1 @@ + +untracked + EOF + cat >expect.lstree <<-EOF && + HEAD + file2 + untracked + EOF + test_path_is_missing file2 && test_path_is_missing untracked && test_path_is_missing HEAD && @@ -83,18 +83,21 @@ test_expect_success 'stash save --patch --all fails' ' test_must_fail git stash --patch --all ' -git clean --force --quiet +test_expect_success 'clean up untracked/untracked file to prepare for next tests' ' + git clean --force --quiet -cat >expect <<EOF - M file -?? HEAD -?? actual -?? expect -?? file2 -?? untracked/ -EOF +' test_expect_success 'stash pop after save --include-untracked leaves files untracked again' ' + cat >expect <<-EOF && + M file + ?? HEAD + ?? actual + ?? expect + ?? file2 + ?? untracked/ + EOF + git stash pop && git status --porcelain >actual && test_cmp expect actual && @@ -102,7 +105,9 @@ test_expect_success 'stash pop after save --include-untracked leaves files untra test untracked = "$(cat untracked/untracked)" ' -git clean --force --quiet -d +test_expect_success 'clean up untracked/ directory to prepare for next tests' ' + git clean --force --quiet -d +' test_expect_success 'stash save -u dirty index' ' echo 4 >file3 && @@ -111,25 +116,24 @@ test_expect_success 'stash save -u dirty index' ' git stash -u ' -blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) -cat >expect <<EOF -diff --git a/file3 b/file3 -new file mode 100644 -index 0000000..$blob ---- /dev/null -+++ b/file3 -@@ -0,0 +1 @@ -+4 -EOF - test_expect_success 'stash save --include-untracked dirty index got stashed' ' + blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) && + cat >expect <<-EOF && + diff --git a/file3 b/file3 + new file mode 100644 + index 0000000..$blob + --- /dev/null + +++ b/file3 + @@ -0,0 +1 @@ + +4 + EOF + git stash pop --index && + test_when_finished "git reset" && git diff --cached >actual && test_cmp expect actual ' -git reset >/dev/null - # Must direct output somewhere where it won't be considered an untracked file test_expect_success 'stash save --include-untracked -q is quiet' ' echo 1 >file5 && @@ -142,23 +146,22 @@ test_expect_success 'stash save --include-untracked removed files' ' rm -f file && git stash save --include-untracked && echo 1 >expect && + test_when_finished "rm -f expect" && test_cmp expect file ' -rm -f expect - test_expect_success 'stash save --include-untracked removed files got stashed' ' git stash pop && test_path_is_missing file ' -cat >.gitignore <<EOF -.gitignore -ignored -ignored.d/ -EOF - test_expect_success 'stash save --include-untracked respects .gitignore' ' + cat >.gitignore <<-EOF && + .gitignore + ignored + ignored.d/ + EOF + echo ignored >ignored && mkdir ignored.d && echo ignored >ignored.d/untracked && @@ -214,12 +217,12 @@ test_expect_success 'stash push with $IFS character' ' test_path_is_file bar ' -cat >.gitignore <<EOF -ignored -ignored.d/* -EOF - test_expect_success 'stash previously ignored file' ' + cat >.gitignore <<-EOF && + ignored + ignored.d/* + EOF + git reset HEAD && git add .gitignore && git commit -m "Add .gitignore" && |