summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-03-28 14:05:58 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-03-28 14:05:58 -0700
commita612436f1479b0f7db9a80f9ba34037ab52bfc12 (patch)
tree93e6df16e4907ba48104d4983a8e380005eb2d48
parentMerge branch 'sb/checkout-recurse-submodules' (diff)
parentstash: keep untracked files intact in stash -k (diff)
downloadtgif-a612436f1479b0f7db9a80f9ba34037ab52bfc12.tar.xz
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
-rwxr-xr-xgit-stash.sh12
-rwxr-xr-xt/t3903-stash.sh16
-rwxr-xr-xt/t3904-stash-patch.sh8
3 files changed, 30 insertions, 6 deletions
diff --git a/git-stash.sh b/git-stash.sh
index 9c70662cc8..2fb651b2b8 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -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
}
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 89877e4b52..b71d1e659e 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -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
diff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh
index 38e730090f..83744f8c93 100755
--- a/t/t3904-stash-patch.sh
+++ b/t/t3904-stash-patch.sh
@@ -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
'