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
This commit is contained in:
Junio C Hamano 2017-03-28 14:05:58 -07:00
commit a612436f14
3 changed files with 30 additions and 6 deletions

View File

@ -299,12 +299,12 @@ push_stash () {
then
if test $# != 0
then
git reset ${GIT_QUIET:+-q} -- "$@"
git reset -q -- "$@"
git ls-files -z --modified -- "$@" |
git checkout-index -z --force --stdin
git clean --force ${GIT_QUIET:+-q} -d -- "$@"
git clean --force -q -d -- "$@"
else
git reset --hard ${GIT_QUIET:+-q}
git reset --hard -q
fi
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
if test -n "$untracked"
@ -314,7 +314,9 @@ push_stash () {
if test "$keep_index" = "t" && test -n "$i_tree"
then
git read-tree --reset -u $i_tree
git read-tree --reset $i_tree
git ls-files -z --modified -- "$@" |
git checkout-index -z --force --stdin
fi
else
git apply -R < "$TMP-patch" ||
@ -322,7 +324,7 @@ push_stash () {
if test "$keep_index" != "t"
then
git reset
git reset -q -- "$@"
fi
fi
}

View File

@ -663,7 +663,7 @@ test_expect_success 'stash apply shows status same as git status (relative to cu
sane_unset GIT_MERGE_VERBOSITY &&
git stash apply
) |
sed -e 1,2d >actual && # drop "Saved..." and "HEAD is now..."
sed -e 1d >actual && # drop "Saved..."
test_i18ncmp expect actual
'
@ -907,4 +907,18 @@ test_expect_success 'stash without verb with pathspec' '
test_path_is_file bar
'
test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
git reset &&
>foo &&
>bar &&
git add foo bar &&
git commit -m "test" &&
echo "foo" >foo &&
echo "bar" >bar &&
git stash -k -- foo &&
test "",bar = $(cat foo),$(cat bar) &&
git stash pop &&
test foo,bar = $(cat foo),$(cat bar)
'
test_done

View File

@ -77,6 +77,14 @@ test_expect_success 'git stash --no-keep-index -p' '
verify_state dir/foo work index
'
test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
set_state HEAD HEADfile_work HEADfile_index &&
set_state dir/foo work index &&
echo y | git stash push -p --no-keep-index -- HEAD &&
verify_state HEAD committed committed &&
verify_state dir/foo work index
'
test_expect_success 'none of this moved HEAD' '
verify_saved_head
'