Skip to content

Commit 9eb765d

Browse files
committed
Merge branch 'bc/unstash-clean-crufts'
* bc/unstash-clean-crufts: git-stash: remove untracked/ignored directories when stashed t/t3905: add missing '&&' linkage git-stash.sh: fix typo in error message t/t3905: use the name 'actual' for test output, swap arguments to test_cmp
2 parents 7af4d34 + 7474b8b commit 9eb765d

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

git-stash.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ save_stash () {
211211

212212
if test -n "$patch_mode" && test -n "$untracked"
213213
then
214-
die "Can't use --patch and ---include-untracked or --all at the same time"
214+
die "Can't use --patch and --include-untracked or --all at the same time"
215215
fi
216216

217217
stash_msg="$*"
@@ -240,7 +240,7 @@ save_stash () {
240240
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
241241
if test -n "$untracked"
242242
then
243-
git clean --force --quiet $CLEAN_X_OPTION
243+
git clean --force --quiet -d $CLEAN_X_OPTION
244244
fi
245245

246246
if test "$keep_index" = "t" && test -n $i_tree

t/t3905-stash-include-untracked.sh

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ test_expect_success 'stash save --include-untracked some dirty working directory
1717
echo 3 > file &&
1818
test_tick &&
1919
echo 1 > file2 &&
20+
mkdir untracked &&
21+
echo untracked >untracked/untracked &&
2022
git stash --include-untracked &&
2123
git diff-files --quiet &&
2224
git diff-index --cached --quiet HEAD
2325
'
2426

2527
cat > expect <<EOF
28+
?? actual
2629
?? expect
27-
?? output
2830
EOF
2931

3032
test_expect_success 'stash save --include-untracked cleaned the untracked files' '
31-
git status --porcelain > output
32-
test_cmp output expect
33+
git status --porcelain >actual &&
34+
test_cmp expect actual
3335
'
3436

3537
cat > expect.diff <<EOF
@@ -40,17 +42,26 @@ index 0000000..d00491f
4042
+++ b/file2
4143
@@ -0,0 +1 @@
4244
+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
4352
EOF
4453
cat > expect.lstree <<EOF
4554
file2
55+
untracked
4656
EOF
4757

4858
test_expect_success 'stash save --include-untracked stashed the untracked files' '
4959
test "!" -f file2 &&
50-
git diff HEAD..stash^3 -- file2 > output &&
51-
test_cmp output expect.diff &&
52-
git ls-tree --name-only stash^3: > output &&
53-
test_cmp output expect.lstree
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
5465
'
5566
test_expect_success 'stash save --patch --include-untracked fails' '
5667
test_must_fail git stash --patch --include-untracked
@@ -64,18 +75,21 @@ git clean --force --quiet
6475

6576
cat > expect <<EOF
6677
M file
78+
?? actual
6779
?? expect
6880
?? file2
69-
?? output
81+
?? untracked/
7082
EOF
7183

7284
test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
7385
git stash pop &&
74-
git status --porcelain > output
75-
test_cmp output expect
86+
git status --porcelain >actual &&
87+
test_cmp expect actual &&
88+
test "1" = "`cat file2`" &&
89+
test untracked = "`cat untracked/untracked`"
7690
'
7791

78-
git clean --force --quiet
92+
git clean --force --quiet -d
7993

8094
test_expect_success 'stash save -u dirty index' '
8195
echo 4 > file3 &&
@@ -96,8 +110,8 @@ EOF
96110

97111
test_expect_success 'stash save --include-untracked dirty index got stashed' '
98112
git stash pop --index &&
99-
git diff --cached > output &&
100-
test_cmp output expect
113+
git diff --cached >actual &&
114+
test_cmp expect actual
101115
'
102116

103117
git reset > /dev/null
@@ -125,30 +139,36 @@ test_expect_success 'stash save --include-untracked removed files got stashed' '
125139
cat > .gitignore <<EOF
126140
.gitignore
127141
ignored
142+
ignored.d/
128143
EOF
129144

130145
test_expect_success 'stash save --include-untracked respects .gitignore' '
131146
echo ignored > ignored &&
147+
mkdir ignored.d &&
148+
echo ignored >ignored.d/untracked &&
132149
git stash -u &&
133150
test -s ignored &&
151+
test -s ignored.d/untracked &&
134152
test -s .gitignore
135153
'
136154

137155
test_expect_success 'stash save -u can stash with only untracked files different' '
138156
echo 4 > file4 &&
139-
git stash -u
157+
git stash -u &&
140158
test "!" -f file4
141159
'
142160

143161
test_expect_success 'stash save --all does not respect .gitignore' '
144162
git stash -a &&
145163
test "!" -f ignored &&
164+
test "!" -e ignored.d &&
146165
test "!" -f .gitignore
147166
'
148167

149168
test_expect_success 'stash save --all is stash poppable' '
150169
git stash pop &&
151170
test -s ignored &&
171+
test -s ignored.d/untracked &&
152172
test -s .gitignore
153173
'
154174

0 commit comments

Comments
 (0)