Thanks Marc for catching the regression I almost introduced and Junio for the review of the second patch. Here's a re-roll that should fix the issues of v2. Interdiff below: diff --git a/git-stash.sh b/git-stash.sh index 7a4ec98f6b..dbedc7fb9f 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -39,7 +39,7 @@ fi no_changes () { git diff-index --quiet --cached HEAD --ignore-submodules -- "$@" && git diff-files --quiet --ignore-submodules -- "$@" && - (test -z "$untracked" || test -z "$(untracked_files $@)") + (test -z "$untracked" || test -z "$(untracked_files "$@")") } untracked_files () { @@ -320,11 +320,14 @@ push_stash () { git clean --force --quiet -d $CLEAN_X_OPTION -- "$@" fi - if test $# != 0 && git ls-files --error-unmatch -- "$@" >/dev/null 2>/dev/null + if test $# != 0 then - git add -u -- "$@" | - git checkout-index -z --force --stdin - git diff-index -p --cached --binary HEAD -- "$@" | git apply --index -R + if git ls-files --error-unmatch -- "$@" >/dev/null 2>/dev/null + then + git add -u -- "$@" | + git checkout-index -z --force --stdin + git diff-index -p --cached --binary HEAD -- "$@" | git apply --index -R + fi else git reset --hard -q fi diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 5e7078c083..7efc52fe11 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1103,6 +1103,15 @@ test_expect_success 'stash -u -- <untracked> doesnt print error' ' test_line_count = 0 actual ' +test_expect_success 'stash -u -- <untracked> leaves rest of working tree in place' ' + >tracked && + git add tracked && + >untracked && + git stash push -u -- untracked && + test_path_is_missing untracked && + test_path_is_file tracked +' + test_expect_success 'stash -u -- <non-existant> shows no changes when there are none' ' git stash push -u -- non-existant >actual && echo "No local changes to save" >expect && Thomas Gummerer (2): stash push: avoid printing errors stash push -u: don't create empty stash git-stash.sh | 11 +++++++---- t/t3903-stash.sh | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) -- 2.16.2.804.g6dcf76e11