Merge branch 'tg/stash-untracked-with-pathspec-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 9 Apr 2018 23:25:45 +0000 (08:25 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Apr 2018 23:25:45 +0000 (08:25 +0900)
"git stash push -u -- <pathspec>" gave an unnecessary and confusing
error message when there was no tracked files that match the
<pathspec>, which has been fixed.

* tg/stash-untracked-with-pathspec-fix:
stash: drop superfluos pathspec parameter
stash push -u: don't create empty stash
stash push: avoid printing errors
stash: fix nonsense pipeline

1  2 
git-stash.sh
diff --combined git-stash.sh
index fc8f8ae6401dddcceaa82f9e9c748f5c185536d6,d31924aea3a03d6f7efc66c03a293406821f1af2..94793c1a913abf569ff9101d935c355b9eb27648
@@@ -39,7 -39,7 +39,7 @@@ f
  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 () {
@@@ -76,12 -76,6 +76,12 @@@ create_stash () 
                        shift
                        stash_msg=${1?"BUG: create_stash () -m requires an argument"}
                        ;;
 +              -m*)
 +                      stash_msg=${1#-m}
 +                      ;;
 +              --message=*)
 +                      stash_msg=${1#--message=}
 +                      ;;
                -u|--include-untracked)
                        shift
                        untracked=${1?"BUG: create_stash () -u requires an argument"}
@@@ -199,12 -193,6 +199,12 @@@ store_stash () 
                        shift
                        stash_msg="$1"
                        ;;
 +              -m*)
 +                      stash_msg=${1#-m}
 +                      ;;
 +              --message=*)
 +                      stash_msg=${1#--message=}
 +                      ;;
                -q|--quiet)
                        quiet=t
                        ;;
@@@ -263,12 -251,6 +263,12 @@@ push_stash () 
                        test -z ${1+x} && usage
                        stash_msg=$1
                        ;;
 +              -m*)
 +                      stash_msg=${1#-m}
 +                      ;;
 +              --message=*)
 +                      stash_msg=${1#--message=}
 +                      ;;
                --help)
                        show_help
                        ;;
                        ;;
                -*)
                        option="$1"
 -                      # TRANSLATORS: $option is an invalid option, like
 -                      # `--blah-blah'. The 7 spaces at the beginning of the
 -                      # second line correspond to "error: ". So you should line
 -                      # up the second line with however many characters the
 -                      # translation of "error: " takes in your language. E.g. in
 -                      # English this is:
 -                      #
 -                      #    $ git stash save --blah-blah 2>&1 | head -n 2
 -                      #    error: unknown option for 'stash save': --blah-blah
 -                      #           To provide a message, use git stash save -- '--blah-blah'
 -                      eval_gettextln "error: unknown option for 'stash save': \$option
 -       To provide a message, use git stash save -- '\$option'"
 +                      eval_gettextln "error: unknown option for 'stash push': \$option"
                        usage
                        ;;
                *)
        if test -z "$patch_mode"
        then
                test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
-               if test -n "$untracked"
+               if test -n "$untracked" && test $# = 0
                then
-                       git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
+                       git clean --force --quiet -d $CLEAN_X_OPTION
                fi
  
                if test $# != 0
                then
-                       git add -u -- "$@" |
-                       git checkout-index -z --force --stdin
-                       git diff-index -p --cached --binary HEAD -- "$@" | git apply --index -R
+                       test -z "$untracked" && UPDATE_OPTION="-u" || UPDATE_OPTION=
+                       test "$untracked" = "all" && FORCE_OPTION="--force" || FORCE_OPTION=
+                       git add $UPDATE_OPTION $FORCE_OPTION -- "$@"
+                       git diff-index -p --cached --binary HEAD -- "$@" |
+                       git apply --index -R
                else
                        git reset --hard -q
                fi