git-stash: remove untracked/ignored directories when stashed
The two new stash options --include-untracked and --all do not remove the untracked and/or ignored files that are stashed if those files reside in a subdirectory. e.g. the following sequence fails: mkdir untracked && echo hello >untracked/file.txt && git stash --include-untracked && test ! -f untracked/file.txt Within the git-stash script, git-clean is used to remove the untracked/ignored files, but since the -d option was not supplied, it does not remove directories. So, add -d to the git-clean arguments, and update the tests to test this functionality. Reported-by: Hilco Wijbenga <hilco.wijbenga@gmail.com> Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Casey committed
Aug 26, 2011 at 19:59 UTC
7474b8b452f2600bd2a9e03f67b83b489aeadb37
2 files changed
+24
-4
git-stash.sh
+1
-1
@@ -228,7 +228,7 @@ save_stash () {
228
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
229
if test -n "$untracked"
230
then
231
- git clean --force --quiet $CLEAN_X_OPTION
231
+ git clean --force --quiet -d $CLEAN_X_OPTION
232
fi
233
234
if test "$keep_index" = "t" && test -n $i_tree
t/t3905-stash-include-untracked.sh
+23
-3
@@ -17,6 +17,8 @@ test_expect_success 'stash save --include-untracked some dirty working directory
17
echo 3 > file &&
18
test_tick &&
19
echo 1 > file2 &&
20
+ mkdir untracked &&
21
+ echo untracked >untracked/untracked &&
22
git stash --include-untracked &&
23
git diff-files --quiet &&
24
git diff-index --cached --quiet HEAD
@@ -40,14 +42,23 @@ index 0000000..d00491f
42
+++ b/file2
43
@@ -0,0 +1 @@
44
+1
45
+diff --git a/untracked/untracked b/untracked/untracked
46
+new file mode 100644
47
+index 0000000..5a72eb2
48
+--- /dev/null
49
++++ b/untracked/untracked
50
+@@ -0,0 +1 @@
51
++untracked
52
EOF
53
cat > expect.lstree <<EOF
54
file2
55
+untracked
56
EOF
57
58
test_expect_success 'stash save --include-untracked stashed the untracked files' '
59
test "!" -f file2 &&
50
- git diff HEAD..stash^3 -- file2 >actual &&
60
+ test ! -e untracked &&
61
+ git diff HEAD stash^3 -- file2 untracked >actual &&
62
test_cmp expect.diff actual &&
63
git ls-tree --name-only stash^3: >actual &&
64
test_cmp expect.lstree actual
@@ -67,15 +78,18 @@ cat > expect <<EOF
78
?? actual
79
?? expect
80
?? file2
81
+?? untracked/
82
EOF
83
84
test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
85
git stash pop &&
86
git status --porcelain >actual &&
75
- test_cmp expect actual
87
+ test_cmp expect actual &&
88
+ test "1" = "`cat file2`" &&
89
+ test untracked = "`cat untracked/untracked`"
90
'
91
78
-git clean --force --quiet
92
+git clean --force --quiet -d
93
94
test_expect_success 'stash save -u dirty index' '
95
echo 4 > file3 &&
@@ -125,12 +139,16 @@ test_expect_success 'stash save --include-untracked removed files got stashed' '
139
cat > .gitignore <<EOF
140
.gitignore
141
ignored
142
+ignored.d/
143
EOF
144
145
test_expect_success 'stash save --include-untracked respects .gitignore' '
146
echo ignored > ignored &&
147
+ mkdir ignored.d &&
148
+ echo ignored >ignored.d/untracked &&
149
git stash -u &&
150
test -s ignored &&
151
+ test -s ignored.d/untracked &&
152
test -s .gitignore
153
'
154
@@ -143,12 +161,14 @@ test_expect_success 'stash save -u can stash with only untracked files different
161
test_expect_success 'stash save --all does not respect .gitignore' '
162
git stash -a &&
163
test "!" -f ignored &&
164
+ test "!" -e ignored.d &&
165
test "!" -f .gitignore
166
'
167
168
test_expect_success 'stash save --all is stash poppable' '
169
git stash pop &&
170
test -s ignored &&
171
+ test -s ignored.d/untracked &&
172
test -s .gitignore
173
'
174