@@ -8,65 +8,67 @@ test_description='Test git stash --include-untracked'
88. ./test-lib.sh
99
1010test_expect_success ' stash save --include-untracked some dirty working directory' '
11- echo 1 > file &&
11+ echo 1 >file &&
1212 git add file &&
1313 test_tick &&
1414 git commit -m initial &&
15- echo 2 > file &&
15+ echo 2 >file &&
1616 git add file &&
17- echo 3 > file &&
17+ echo 3 >file &&
1818 test_tick &&
19- echo 1 > file2 &&
20- echo 1 > HEAD &&
19+ echo 1 >file2 &&
20+ echo 1 >HEAD &&
2121 mkdir untracked &&
2222 echo untracked >untracked/untracked &&
2323 git stash --include-untracked &&
2424 git diff-files --quiet &&
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+ one_blob=$(echo 1 | git hash-object --stdin) &&
40+ tracked=$(git rev-parse --short "$one_blob") &&
41+ untracked_blob=$(echo untracked | git hash-object --stdin) &&
42+ untracked=$(git rev-parse --short "$untracked_blob") &&
43+ cat >expect.diff <<-EOF &&
44+ diff --git a/HEAD b/HEAD
45+ new file mode 100644
46+ index 0000000..$tracked
47+ --- /dev/null
48+ +++ b/HEAD
49+ @@ -0,0 +1 @@
50+ +1
51+ diff --git a/file2 b/file2
52+ new file mode 100644
53+ index 0000000..$tracked
54+ --- /dev/null
55+ +++ b/file2
56+ @@ -0,0 +1 @@
57+ +1
58+ diff --git a/untracked/untracked b/untracked/untracked
59+ new file mode 100644
60+ index 0000000..$untracked
61+ --- /dev/null
62+ +++ b/untracked/untracked
63+ @@ -0,0 +1 @@
64+ +untracked
65+ EOF
66+ cat >expect.lstree <<-EOF &&
67+ HEAD
68+ file2
69+ untracked
70+ EOF
71+
7072 test_path_is_missing file2 &&
7173 test_path_is_missing untracked &&
7274 test_path_is_missing HEAD &&
@@ -83,93 +85,99 @@ test_expect_success 'stash save --patch --all fails' '
8385 test_must_fail git stash --patch --all
8486'
8587
86- git clean --force --quiet
88+ test_expect_success ' clean up untracked/untracked file to prepare for next tests' '
89+ git clean --force --quiet
8790
88- cat > expect << EOF
89- M file
90- ?? HEAD
91- ?? actual
92- ?? expect
93- ?? file2
94- ?? untracked/
95- EOF
91+ '
9692
9793test_expect_success ' stash pop after save --include-untracked leaves files untracked again' '
94+ cat >expect <<-EOF &&
95+ M file
96+ ?? HEAD
97+ ?? actual
98+ ?? expect
99+ ?? file2
100+ ?? untracked/
101+ EOF
102+
98103 git stash pop &&
99104 git status --porcelain >actual &&
100105 test_cmp expect actual &&
101- test "1" = "$(cat file2)" &&
102- test untracked = "$(cat untracked/untracked)"
106+ echo 1 >expect_file2 &&
107+ test_cmp expect_file2 file2 &&
108+ echo untracked >untracked_expect &&
109+ test_cmp untracked_expect untracked/untracked
103110'
104111
105- git clean --force --quiet -d
112+ test_expect_success ' clean up untracked/ directory to prepare for next tests' '
113+ git clean --force --quiet -d
114+ '
106115
107116test_expect_success ' stash save -u dirty index' '
108- echo 4 > file3 &&
117+ echo 4 >file3 &&
109118 git add file3 &&
110119 test_tick &&
111120 git stash -u
112121'
113122
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-
125123test_expect_success ' stash save --include-untracked dirty index got stashed' '
124+ four_blob=$(echo 4 | git hash-object --stdin) &&
125+ blob=$(git rev-parse --short "$four_blob") &&
126+ cat >expect <<-EOF &&
127+ diff --git a/file3 b/file3
128+ new file mode 100644
129+ index 0000000..$blob
130+ --- /dev/null
131+ +++ b/file3
132+ @@ -0,0 +1 @@
133+ +4
134+ EOF
135+
126136 git stash pop --index &&
137+ test_when_finished "git reset" &&
127138 git diff --cached >actual &&
128139 test_cmp expect actual
129140'
130141
131- git reset > /dev/null
132-
133142# Must direct output somewhere where it won't be considered an untracked file
134143test_expect_success ' stash save --include-untracked -q is quiet' '
135- echo 1 > file5 &&
136- git stash save --include-untracked --quiet > .git/stash-output.out 2>&1 &&
144+ echo 1 >file5 &&
145+ git stash save --include-untracked --quiet >.git/stash-output.out 2>&1 &&
137146 test_line_count = 0 .git/stash-output.out &&
138147 rm -f .git/stash-output.out
139148'
140149
141150test_expect_success ' stash save --include-untracked removed files' '
142151 rm -f file &&
143152 git stash save --include-untracked &&
144- echo 1 > expect &&
153+ echo 1 >expect &&
154+ test_when_finished "rm -f expect" &&
145155 test_cmp expect file
146156'
147157
148- rm -f expect
149-
150158test_expect_success ' stash save --include-untracked removed files got stashed' '
151159 git stash pop &&
152160 test_path_is_missing file
153161'
154162
155- cat > .gitignore << EOF
156- .gitignore
157- ignored
158- ignored.d/
159- EOF
160-
161163test_expect_success ' stash save --include-untracked respects .gitignore' '
162- echo ignored > ignored &&
164+ cat >.gitignore <<-EOF &&
165+ .gitignore
166+ ignored
167+ ignored.d/
168+ EOF
169+
170+ echo ignored >ignored &&
163171 mkdir ignored.d &&
164172 echo ignored >ignored.d/untracked &&
165173 git stash -u &&
166- test -s ignored &&
167- test -s ignored.d/untracked &&
168- test -s .gitignore
174+ test_file_not_empty ignored &&
175+ test_file_not_empty ignored.d/untracked &&
176+ test_file_not_empty .gitignore
169177'
170178
171179test_expect_success ' stash save -u can stash with only untracked files different' '
172- echo 4 > file4 &&
180+ echo 4 >file4 &&
173181 git stash -u &&
174182 test_path_is_missing file4
175183'
@@ -183,9 +191,9 @@ test_expect_success 'stash save --all does not respect .gitignore' '
183191
184192test_expect_success ' stash save --all is stash poppable' '
185193 git stash pop &&
186- test -s ignored &&
187- test -s ignored.d/untracked &&
188- test -s .gitignore
194+ test_file_not_empty ignored &&
195+ test_file_not_empty ignored.d/untracked &&
196+ test_file_not_empty .gitignore
189197'
190198
191199test_expect_success ' stash push --include-untracked with pathspec' '
@@ -214,17 +222,17 @@ test_expect_success 'stash push with $IFS character' '
214222 test_path_is_file bar
215223'
216224
217- cat > .gitignore << EOF
218- ignored
219- ignored.d/*
220- EOF
221-
222225test_expect_success ' stash previously ignored file' '
226+ cat >.gitignore <<-EOF &&
227+ ignored
228+ ignored.d/*
229+ EOF
230+
223231 git reset HEAD &&
224232 git add .gitignore &&
225233 git commit -m "Add .gitignore" &&
226234 >ignored.d/foo &&
227- echo "!ignored.d/foo" >> .gitignore &&
235+ echo "!ignored.d/foo" >>.gitignore &&
228236 git stash save --include-untracked &&
229237 test_path_is_missing ignored.d/foo &&
230238 git stash pop &&
0 commit comments