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>

Denton Liu committed Feb 8, 2021 at 23:28 UTC bbaa45c3aace10e25ae9dd966e867796fbf440ad
1 file changed +75 -72
t/t3905-stash-include-untracked.sh
+75 -72
@@ -25,48 +25,48 @@ test_expect_success 'stash save --include-untracked some dirty working directory
25 git diff-index --cached --quiet HEAD
26 '
27
28 -cat >expect <<EOF
29 -?? actual
30 -?? expect
31 -EOF
32 -
28 test_expect_success 'stash save --include-untracked cleaned the untracked files' '
29 + cat >expect <<-EOF &&
30 + ?? actual
31 + ?? expect
32 + EOF
33 +
34 git status --porcelain >actual &&
35 test_cmp expect actual
36 '
37
38 -tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin))
39 -untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin))
40 -cat >expect.diff <<EOF
41 -diff --git a/HEAD b/HEAD
42 -new file mode 100644
43 -index 0000000..$tracked
44 ---- /dev/null
45 -+++ b/HEAD
46 -@@ -0,0 +1 @@
47 -+1
48 -diff --git a/file2 b/file2
49 -new file mode 100644
50 -index 0000000..$tracked
51 ---- /dev/null
52 -+++ b/file2
53 -@@ -0,0 +1 @@
54 -+1
55 -diff --git a/untracked/untracked b/untracked/untracked
56 -new file mode 100644
57 -index 0000000..$untracked
58 ---- /dev/null
59 -+++ b/untracked/untracked
60 -@@ -0,0 +1 @@
61 -+untracked
62 -EOF
63 -cat >expect.lstree <<EOF
64 -HEAD
65 -file2
66 -untracked
67 -EOF
68 -
38 test_expect_success 'stash save --include-untracked stashed the untracked files' '
39 + tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) &&
40 + untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) &&
41 + cat >expect.diff <<-EOF &&
42 + diff --git a/HEAD b/HEAD
43 + new file mode 100644
44 + index 0000000..$tracked
45 + --- /dev/null
46 + +++ b/HEAD
47 + @@ -0,0 +1 @@
48 + +1
49 + diff --git a/file2 b/file2
50 + new file mode 100644
51 + index 0000000..$tracked
52 + --- /dev/null
53 + +++ b/file2
54 + @@ -0,0 +1 @@
55 + +1
56 + diff --git a/untracked/untracked b/untracked/untracked
57 + new file mode 100644
58 + index 0000000..$untracked
59 + --- /dev/null
60 + +++ b/untracked/untracked
61 + @@ -0,0 +1 @@
62 + +untracked
63 + EOF
64 + cat >expect.lstree <<-EOF &&
65 + HEAD
66 + file2
67 + untracked
68 + EOF
69 +
70 test_path_is_missing file2 &&
71 test_path_is_missing untracked &&
72 test_path_is_missing HEAD &&
@@ -83,18 +83,21 @@ test_expect_success 'stash save --patch --all fails' '
83 test_must_fail git stash --patch --all
84 '
85
86 -git clean --force --quiet
86 +test_expect_success 'clean up untracked/untracked file to prepare for next tests' '
87 + git clean --force --quiet
88
88 -cat >expect <<EOF
89 - M file
90 -?? HEAD
91 -?? actual
92 -?? expect
93 -?? file2
94 -?? untracked/
95 -EOF
89 +'
90
91 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
92 + cat >expect <<-EOF &&
93 + M file
94 + ?? HEAD
95 + ?? actual
96 + ?? expect
97 + ?? file2
98 + ?? untracked/
99 + EOF
100 +
101 git stash pop &&
102 git status --porcelain >actual &&
103 test_cmp expect actual &&
@@ -102,7 +105,9 @@ test_expect_success 'stash pop after save --include-untracked leaves files untra
105 test untracked = "$(cat untracked/untracked)"
106 '
107
105 -git clean --force --quiet -d
108 +test_expect_success 'clean up untracked/ directory to prepare for next tests' '
109 + git clean --force --quiet -d
110 +'
111
112 test_expect_success 'stash save -u dirty index' '
113 echo 4 >file3 &&
@@ -111,25 +116,24 @@ test_expect_success 'stash save -u dirty index' '
116 git stash -u
117 '
118
114 -blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin))
115 -cat >expect <<EOF
116 -diff --git a/file3 b/file3
117 -new file mode 100644
118 -index 0000000..$blob
119 ---- /dev/null
120 -+++ b/file3
121 -@@ -0,0 +1 @@
122 -+4
123 -EOF
124 -
119 test_expect_success 'stash save --include-untracked dirty index got stashed' '
120 + blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) &&
121 + cat >expect <<-EOF &&
122 + diff --git a/file3 b/file3
123 + new file mode 100644
124 + index 0000000..$blob
125 + --- /dev/null
126 + +++ b/file3
127 + @@ -0,0 +1 @@
128 + +4
129 + EOF
130 +
131 git stash pop --index &&
132 + test_when_finished "git reset" &&
133 git diff --cached >actual &&
134 test_cmp expect actual
135 '
136
131 -git reset >/dev/null
132 -
137 # Must direct output somewhere where it won't be considered an untracked file
138 test_expect_success 'stash save --include-untracked -q is quiet' '
139 echo 1 >file5 &&
@@ -142,23 +146,22 @@ test_expect_success 'stash save --include-untracked removed files' '
146 rm -f file &&
147 git stash save --include-untracked &&
148 echo 1 >expect &&
149 + test_when_finished "rm -f expect" &&
150 test_cmp expect file
151 '
152
148 -rm -f expect
149 -
153 test_expect_success 'stash save --include-untracked removed files got stashed' '
154 git stash pop &&
155 test_path_is_missing file
156 '
157
155 -cat >.gitignore <<EOF
156 -.gitignore
157 -ignored
158 -ignored.d/
159 -EOF
160 -
158 test_expect_success 'stash save --include-untracked respects .gitignore' '
159 + cat >.gitignore <<-EOF &&
160 + .gitignore
161 + ignored
162 + ignored.d/
163 + EOF
164 +
165 echo ignored >ignored &&
166 mkdir ignored.d &&
167 echo ignored >ignored.d/untracked &&
@@ -214,12 +217,12 @@ test_expect_success 'stash push with $IFS character' '
217 test_path_is_file bar
218 '
219
217 -cat >.gitignore <<EOF
218 -ignored
219 -ignored.d/*
220 -EOF
221 -
220 test_expect_success 'stash previously ignored file' '
221 + cat >.gitignore <<-EOF &&
222 + ignored
223 + ignored.d/*
224 + EOF
225 +
226 git reset HEAD &&
227 git add .gitignore &&
228 git commit -m "Add .gitignore" &&