Skip to content

Commit 0ca2f32

Browse files
committed
Merge branch 'nm/stash-untracked'
"git stash -u" used the contents of the committed version of the ".gitignore" file to decide which paths are ignored, even when the file has local changes. The command has been taught to instead use the locally modified contents. * nm/stash-untracked: stash: clean untracked files before reset
2 parents fa2a4bb + bbffd87 commit 0ca2f32

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

git-stash.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ push_stash () {
300300

301301
if test -z "$patch_mode"
302302
then
303+
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
304+
if test -n "$untracked"
305+
then
306+
git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
307+
fi
308+
303309
if test $# != 0
304310
then
305311
git reset -q -- "$@"
@@ -309,11 +315,6 @@ push_stash () {
309315
else
310316
git reset --hard -q
311317
fi
312-
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
313-
if test -n "$untracked"
314-
then
315-
git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
316-
fi
317318

318319
if test "$keep_index" = "t" && test -n "$i_tree"
319320
then

t/t3905-stash-include-untracked.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,21 @@ test_expect_success 'stash push with $IFS character' '
211211
test_path_is_file bar
212212
'
213213

214+
cat > .gitignore <<EOF
215+
ignored
216+
ignored.d/*
217+
EOF
218+
219+
test_expect_success 'stash previously ignored file' '
220+
git reset HEAD &&
221+
git add .gitignore &&
222+
git commit -m "Add .gitignore" &&
223+
>ignored.d/foo &&
224+
echo "!ignored.d/foo" >> .gitignore &&
225+
git stash save --include-untracked &&
226+
test_path_is_missing ignored.d/foo &&
227+
git stash pop &&
228+
test_path_is_file ignored.d/foo
229+
'
230+
214231
test_done

0 commit comments

Comments
 (0)