@@ -8,65 +8,67 @@ test_description='Test git stash --include-untracked'
8
8
. ./test-lib.sh
9
9
10
10
test_expect_success ' stash save --include-untracked some dirty working directory' '
11
- echo 1 > file &&
11
+ echo 1 >file &&
12
12
git add file &&
13
13
test_tick &&
14
14
git commit -m initial &&
15
- echo 2 > file &&
15
+ echo 2 >file &&
16
16
git add file &&
17
- echo 3 > file &&
17
+ echo 3 >file &&
18
18
test_tick &&
19
- echo 1 > file2 &&
20
- echo 1 > HEAD &&
19
+ echo 1 >file2 &&
20
+ echo 1 >HEAD &&
21
21
mkdir untracked &&
22
22
echo untracked >untracked/untracked &&
23
23
git stash --include-untracked &&
24
24
git diff-files --quiet &&
25
25
git diff-index --cached --quiet HEAD
26
26
'
27
27
28
- cat > expect << EOF
29
- ?? actual
30
- ?? expect
31
- EOF
32
-
33
28
test_expect_success ' stash save --include-untracked cleaned the untracked files' '
29
+ cat >expect <<-EOF &&
30
+ ?? actual
31
+ ?? expect
32
+ EOF
33
+
34
34
git status --porcelain >actual &&
35
35
test_cmp expect actual
36
36
'
37
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
-
69
38
test_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
+
70
72
test_path_is_missing file2 &&
71
73
test_path_is_missing untracked &&
72
74
test_path_is_missing HEAD &&
@@ -83,93 +85,99 @@ test_expect_success 'stash save --patch --all fails' '
83
85
test_must_fail git stash --patch --all
84
86
'
85
87
86
- git clean --force --quiet
88
+ test_expect_success ' clean up untracked/untracked file to prepare for next tests' '
89
+ git clean --force --quiet
87
90
88
- cat > expect << EOF
89
- M file
90
- ?? HEAD
91
- ?? actual
92
- ?? expect
93
- ?? file2
94
- ?? untracked/
95
- EOF
91
+ '
96
92
97
93
test_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
+
98
103
git stash pop &&
99
104
git status --porcelain >actual &&
100
105
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
103
110
'
104
111
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
+ '
106
115
107
116
test_expect_success ' stash save -u dirty index' '
108
- echo 4 > file3 &&
117
+ echo 4 >file3 &&
109
118
git add file3 &&
110
119
test_tick &&
111
120
git stash -u
112
121
'
113
122
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
-
125
123
test_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
+
126
136
git stash pop --index &&
137
+ test_when_finished "git reset" &&
127
138
git diff --cached >actual &&
128
139
test_cmp expect actual
129
140
'
130
141
131
- git reset > /dev/null
132
-
133
142
# Must direct output somewhere where it won't be considered an untracked file
134
143
test_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 &&
137
146
test_line_count = 0 .git/stash-output.out &&
138
147
rm -f .git/stash-output.out
139
148
'
140
149
141
150
test_expect_success ' stash save --include-untracked removed files' '
142
151
rm -f file &&
143
152
git stash save --include-untracked &&
144
- echo 1 > expect &&
153
+ echo 1 >expect &&
154
+ test_when_finished "rm -f expect" &&
145
155
test_cmp expect file
146
156
'
147
157
148
- rm -f expect
149
-
150
158
test_expect_success ' stash save --include-untracked removed files got stashed' '
151
159
git stash pop &&
152
160
test_path_is_missing file
153
161
'
154
162
155
- cat > .gitignore << EOF
156
- .gitignore
157
- ignored
158
- ignored.d/
159
- EOF
160
-
161
163
test_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 &&
163
171
mkdir ignored.d &&
164
172
echo ignored >ignored.d/untracked &&
165
173
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
169
177
'
170
178
171
179
test_expect_success ' stash save -u can stash with only untracked files different' '
172
- echo 4 > file4 &&
180
+ echo 4 >file4 &&
173
181
git stash -u &&
174
182
test_path_is_missing file4
175
183
'
@@ -183,9 +191,9 @@ test_expect_success 'stash save --all does not respect .gitignore' '
183
191
184
192
test_expect_success ' stash save --all is stash poppable' '
185
193
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
189
197
'
190
198
191
199
test_expect_success ' stash push --include-untracked with pathspec' '
@@ -214,17 +222,17 @@ test_expect_success 'stash push with $IFS character' '
214
222
test_path_is_file bar
215
223
'
216
224
217
- cat > .gitignore << EOF
218
- ignored
219
- ignored.d/*
220
- EOF
221
-
222
225
test_expect_success ' stash previously ignored file' '
226
+ cat >.gitignore <<-EOF &&
227
+ ignored
228
+ ignored.d/*
229
+ EOF
230
+
223
231
git reset HEAD &&
224
232
git add .gitignore &&
225
233
git commit -m "Add .gitignore" &&
226
234
>ignored.d/foo &&
227
- echo "!ignored.d/foo" >> .gitignore &&
235
+ echo "!ignored.d/foo" >>.gitignore &&
228
236
git stash save --include-untracked &&
229
237
test_path_is_missing ignored.d/foo &&
230
238
git stash pop &&
0 commit comments