@@ -25,48 +25,48 @@ test_expect_success 'stash save --include-untracked some dirty working directory
2525 git diff-index --cached --quiet HEAD
2626'
2727
28- cat > expect << EOF
29- ?? actual
30- ?? expect
31- EOF
32-
3328test_expect_success ' stash save --include-untracked cleaned the untracked files' '
29+ cat >expect <<-EOF &&
30+ ?? actual
31+ ?? expect
32+ EOF
33+
3434 git status --porcelain >actual &&
3535 test_cmp expect actual
3636'
3737
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-
6938test_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+
7070 test_path_is_missing file2 &&
7171 test_path_is_missing untracked &&
7272 test_path_is_missing HEAD &&
@@ -83,26 +83,31 @@ test_expect_success 'stash save --patch --all fails' '
8383 test_must_fail git stash --patch --all
8484'
8585
86- git clean --force --quiet
86+ test_expect_success ' clean up untracked/untracked file to prepare for next tests' '
87+ git clean --force --quiet
8788
88- cat > expect << EOF
89- M file
90- ?? HEAD
91- ?? actual
92- ?? expect
93- ?? file2
94- ?? untracked/
95- EOF
89+ '
9690
9791test_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+
98101 git stash pop &&
99102 git status --porcelain >actual &&
100103 test_cmp expect actual &&
101104 test "1" = "$(cat file2)" &&
102105 test untracked = "$(cat untracked/untracked)"
103106'
104107
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+ '
106111
107112test_expect_success ' stash save -u dirty index' '
108113 echo 4 >file3 &&
@@ -111,25 +116,24 @@ test_expect_success 'stash save -u dirty index' '
111116 git stash -u
112117'
113118
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-
125119test_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+
126131 git stash pop --index &&
132+ test_when_finished "git reset" &&
127133 git diff --cached >actual &&
128134 test_cmp expect actual
129135'
130136
131- git reset > /dev/null
132-
133137# Must direct output somewhere where it won't be considered an untracked file
134138test_expect_success ' stash save --include-untracked -q is quiet' '
135139 echo 1 >file5 &&
@@ -142,23 +146,22 @@ test_expect_success 'stash save --include-untracked removed files' '
142146 rm -f file &&
143147 git stash save --include-untracked &&
144148 echo 1 >expect &&
149+ test_when_finished "rm -f expect" &&
145150 test_cmp expect file
146151'
147152
148- rm -f expect
149-
150153test_expect_success ' stash save --include-untracked removed files got stashed' '
151154 git stash pop &&
152155 test_path_is_missing file
153156'
154157
155- cat > .gitignore << EOF
156- .gitignore
157- ignored
158- ignored.d/
159- EOF
160-
161158test_expect_success ' stash save --include-untracked respects .gitignore' '
159+ cat >.gitignore <<-EOF &&
160+ .gitignore
161+ ignored
162+ ignored.d/
163+ EOF
164+
162165 echo ignored >ignored &&
163166 mkdir ignored.d &&
164167 echo ignored >ignored.d/untracked &&
@@ -214,12 +217,12 @@ test_expect_success 'stash push with $IFS character' '
214217 test_path_is_file bar
215218'
216219
217- cat > .gitignore << EOF
218- ignored
219- ignored.d/*
220- EOF
221-
222220test_expect_success ' stash previously ignored file' '
221+ cat >.gitignore <<-EOF &&
222+ ignored
223+ ignored.d/*
224+ EOF
225+
223226 git reset HEAD &&
224227 git add .gitignore &&
225228 git commit -m "Add .gitignore" &&
0 commit comments