Skip to content

Commit a612436

Browse files
committed
Merge branch 'tg/stash-push-fixup'
Recent enhancement to "git stash push" command to support pathspec to allow only a subset of working tree changes to be stashed away was found to be too chatty and exposed the internal implementation detail (e.g. when it uses reset to match the index to HEAD before doing other things, output from reset seeped out). These, and other chattyness has been fixed. * tg/stash-push-fixup: stash: keep untracked files intact in stash -k stash: pass the pathspec argument to git reset stash: don't show internal implementation details
2 parents e394fa0 + e0e7f99 commit a612436

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

git-stash.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,12 @@ push_stash () {
299299
then
300300
if test $# != 0
301301
then
302-
git reset ${GIT_QUIET:+-q} -- "$@"
302+
git reset -q -- "$@"
303303
git ls-files -z --modified -- "$@" |
304304
git checkout-index -z --force --stdin
305-
git clean --force ${GIT_QUIET:+-q} -d -- "$@"
305+
git clean --force -q -d -- "$@"
306306
else
307-
git reset --hard ${GIT_QUIET:+-q}
307+
git reset --hard -q
308308
fi
309309
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
310310
if test -n "$untracked"
@@ -314,15 +314,17 @@ push_stash () {
314314

315315
if test "$keep_index" = "t" && test -n "$i_tree"
316316
then
317-
git read-tree --reset -u $i_tree
317+
git read-tree --reset $i_tree
318+
git ls-files -z --modified -- "$@" |
319+
git checkout-index -z --force --stdin
318320
fi
319321
else
320322
git apply -R < "$TMP-patch" ||
321323
die "$(gettext "Cannot remove worktree changes")"
322324

323325
if test "$keep_index" != "t"
324326
then
325-
git reset
327+
git reset -q -- "$@"
326328
fi
327329
fi
328330
}

t/t3903-stash.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ test_expect_success 'stash apply shows status same as git status (relative to cu
663663
sane_unset GIT_MERGE_VERBOSITY &&
664664
git stash apply
665665
) |
666-
sed -e 1,2d >actual && # drop "Saved..." and "HEAD is now..."
666+
sed -e 1d >actual && # drop "Saved..."
667667
test_i18ncmp expect actual
668668
'
669669

@@ -907,4 +907,18 @@ test_expect_success 'stash without verb with pathspec' '
907907
test_path_is_file bar
908908
'
909909

910+
test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
911+
git reset &&
912+
>foo &&
913+
>bar &&
914+
git add foo bar &&
915+
git commit -m "test" &&
916+
echo "foo" >foo &&
917+
echo "bar" >bar &&
918+
git stash -k -- foo &&
919+
test "",bar = $(cat foo),$(cat bar) &&
920+
git stash pop &&
921+
test foo,bar = $(cat foo),$(cat bar)
922+
'
923+
910924
test_done

t/t3904-stash-patch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ test_expect_success 'git stash --no-keep-index -p' '
7777
verify_state dir/foo work index
7878
'
7979

80+
test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
81+
set_state HEAD HEADfile_work HEADfile_index &&
82+
set_state dir/foo work index &&
83+
echo y | git stash push -p --no-keep-index -- HEAD &&
84+
verify_state HEAD committed committed &&
85+
verify_state dir/foo work index
86+
'
87+
8088
test_expect_success 'none of this moved HEAD' '
8189
verify_saved_head
8290
'

0 commit comments

Comments
 (0)