]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'tg/stash-with-pathspec-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 23 Jan 2018 21:16:39 +0000 (13:16 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Jan 2018 21:16:39 +0000 (13:16 -0800)
"git stash -- <pathspec>" incorrectly blew away untracked files in
the directory that matched the pathspec, which has been corrected.

* tg/stash-with-pathspec-fix:
  stash: don't delete untracked files that match pathspec

1  2 
git-stash.sh
t/t3903-stash.sh

diff --combined git-stash.sh
index 1114005ce2829011cde2e6de608a2b90df355fc9,b48b16474865bb9540c0fa108299d77b2f00ecbb..fc8f8ae6401dddcceaa82f9e9c748f5c185536d6
@@@ -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 $# != 0
                then
-                       git reset -q -- "$@"
-                       git ls-files -z --modified -- "$@" |
+                       git add -u -- "$@" |
                        git checkout-index -z --force --stdin
-                       git clean --force -q -d -- "$@"
+                       git diff-index -p --cached --binary HEAD -- "$@" | git apply --index -R
                else
                        git reset --hard -q
                fi
diff --combined t/t3903-stash.sh
index 39c7f2ebd740db097d67b12a68fa35f3fa884fc8,1cd85e70e90d6796c75a94ce73606ef691c4e483..aefde7b1726bdc8d71d2b78e313e29daa2b31a24
@@@ -802,99 -802,6 +802,99 @@@ test_expect_success 'push -m shows righ
        echo "stash@{0}: On master: test message" >expect &&
        git stash list -1 >actual &&
        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' '
@@@ -1064,4 -971,36 +1064,36 @@@ test_expect_success 'stash -k -- <paths
        test foo,bar = $(cat foo),$(cat bar)
  '
  
+ test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' '
+       git reset &&
+       >subdir/untracked &&
+       >subdir/tracked1 &&
+       >subdir/tracked2 &&
+       git add subdir/tracked* &&
+       git stash -- subdir/ &&
+       test_path_is_missing subdir/tracked1 &&
+       test_path_is_missing subdir/tracked2 &&
+       test_path_is_file subdir/untracked &&
+       git stash pop &&
+       test_path_is_file subdir/tracked1 &&
+       test_path_is_file subdir/tracked2 &&
+       test_path_is_file subdir/untracked
+ '
+ test_expect_success 'stash -- <subdir> works with binary files' '
+       git reset &&
+       >subdir/untracked &&
+       >subdir/tracked &&
+       cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
+       git add subdir/tracked* &&
+       git stash -- subdir/ &&
+       test_path_is_missing subdir/tracked &&
+       test_path_is_missing subdir/tracked-binary &&
+       test_path_is_file subdir/untracked &&
+       git stash pop &&
+       test_path_is_file subdir/tracked &&
+       test_path_is_file subdir/tracked-binary &&
+       test_path_is_file subdir/untracked
+ '
  test_done