Merge branch 'ph/stash-save-m-option-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 6 Dec 2017 17:23:42 +0000 (09:23 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Dec 2017 17:23:43 +0000 (09:23 -0800)
In addition to "git stash -m message", the command learned to
accept "git stash -mmessage" form.

* ph/stash-save-m-option-fix:
stash: learn to parse -m/--message like commit does

1  2 
git-stash.sh
t/t3903-stash.sh
diff --combined git-stash.sh
index 4b7495144013b6a224571376a411cdcbcfd055aa,5a5b6b030cb13c6e784529ac364a14361f7976fb..1114005ce2829011cde2e6de608a2b90df355fc9
@@@ -76,6 -76,12 +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"}
@@@ -193,6 -199,12 +199,12 @@@ store_stash () 
                        shift
                        stash_msg="$1"
                        ;;
+               -m*)
+                       stash_msg=${1#-m}
+                       ;;
+               --message=*)
+                       stash_msg=${1#--message=}
+                       ;;
                -q|--quiet)
                        quiet=t
                        ;;
@@@ -251,6 -263,12 +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"
 +              then
 +                      git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
 +              fi
 +
                if test $# != 0
                then
                        git reset -q -- "$@"
                else
                        git reset --hard -q
                fi
 -              test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
 -              if test -n "$untracked"
 -              then
 -                      git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
 -              fi
  
                if test "$keep_index" = "t" && test -n "$i_tree"
                then
diff --combined t/t3903-stash.sh
index 3b1ac1971af1d972b77b3dfe8ae4a56e00e1fa55,c0122c7f3b08e78eee26b74b3e7e613ac28971d3..39c7f2ebd740db097d67b12a68fa35f3fa884fc8
@@@ -444,14 -444,6 +444,14 @@@ test_expect_failure 'stash file to dire
        test foo = "$(cat file/file)"
  '
  
 +test_expect_success 'stash create - no changes' '
 +      git stash clear &&
 +      test_when_finished "git reset --hard HEAD" &&
 +      git reset --hard &&
 +      git stash create >actual &&
 +      test_must_be_empty actual
 +'
 +
  test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
        git stash clear &&
        test_when_finished "git reset --hard HEAD" &&
@@@ -656,20 -648,6 +656,20 @@@ test_expect_success 'stash branch shoul
        git rev-parse stash@{0} --
  '
  
 +test_expect_success 'stash branch should not drop the stash if the apply fails' '
 +      git stash clear &&
 +      git reset HEAD~1 --hard &&
 +      echo foo >file &&
 +      git add file &&
 +      git commit -m initial &&
 +      echo bar >file &&
 +      git stash &&
 +      echo baz >file &&
 +      test_when_finished "git checkout master" &&
 +      test_must_fail git stash branch new_branch stash@{0} &&
 +      git rev-parse stash@{0} --
 +'
 +
  test_expect_success 'stash apply shows status same as git status (relative to current directory)' '
        git stash clear &&
        echo 1 >subdir/subfile1 &&
@@@ -804,6 -782,99 +804,99 @@@ test_expect_success 'push -m shows righ
        test_cmp expect actual
  '
  
+ test_expect_success 'push -m also works without space' '
+       >foo &&
+       git add foo &&
+       git stash push -m"unspaced test message" &&
+       echo "stash@{0}: On master: unspaced test message" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'store -m foo shows right message' '
+       git stash clear &&
+       git reset --hard &&
+       echo quux >bazzy &&
+       git add bazzy &&
+       STASH_ID=$(git stash create) &&
+       git stash store -m "store m" $STASH_ID &&
+       echo "stash@{0}: store m" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'store -mfoo shows right message' '
+       git stash clear &&
+       git reset --hard &&
+       echo quux >bazzy &&
+       git add bazzy &&
+       STASH_ID=$(git stash create) &&
+       git stash store -m"store mfoo" $STASH_ID &&
+       echo "stash@{0}: store mfoo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'store --message=foo shows right message' '
+       git stash clear &&
+       git reset --hard &&
+       echo quux >bazzy &&
+       git add bazzy &&
+       STASH_ID=$(git stash create) &&
+       git stash store --message="store message=foo" $STASH_ID &&
+       echo "stash@{0}: store message=foo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'store --message foo shows right message' '
+       git stash clear &&
+       git reset --hard &&
+       echo quux >bazzy &&
+       git add bazzy &&
+       STASH_ID=$(git stash create) &&
+       git stash store --message "store message foo" $STASH_ID &&
+       echo "stash@{0}: store message foo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'push -mfoo uses right message' '
+       >foo &&
+       git add foo &&
+       git stash push -m"test mfoo" &&
+       echo "stash@{0}: On master: test mfoo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'push --message foo is synonym for -mfoo' '
+       >foo &&
+       git add foo &&
+       git stash push --message "test message foo" &&
+       echo "stash@{0}: On master: test message foo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'push --message=foo is synonym for -mfoo' '
+       >foo &&
+       git add foo &&
+       git stash push --message="test message=foo" &&
+       echo "stash@{0}: On master: test message=foo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'push -m shows right message' '
+       >foo &&
+       git add foo &&
+       git stash push -m "test m foo" &&
+       echo "stash@{0}: On master: test m foo" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+ '
  test_expect_success 'create stores correct message' '
        >foo &&
        git add foo &&
@@@ -822,18 -893,6 +915,18 @@@ test_expect_success 'create with multip
        test_cmp expect actual
  '
  
 +test_expect_success 'create in a detached state' '
 +      test_when_finished "git checkout master" &&
 +      git checkout HEAD~1 &&
 +      >foo &&
 +      git add foo &&
 +      STASH_ID=$(git stash create) &&
 +      HEAD_ID=$(git rev-parse --short HEAD) &&
 +      echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
 +      git show --pretty=%s -s ${STASH_ID} >actual &&
 +      test_cmp expect actual
 +'
 +
  test_expect_success 'stash -- <pathspec> stashes and restores the file' '
        >foo &&
        >bar &&