Merge branch 'ps/stash-push-pathspec-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Sat, 24 Jun 2017 22:29:30 +0000 (15:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 24 Jun 2017 22:29:30 +0000 (15:29 -0700)
"git stash push <pathspec>" did not work from a subdirectory at all.
Bugfix for a topic in v2.13

* ps/stash-push-pathspec-fix:
git-stash: fix pushing stash with pathspec from subdir

git-stash.sh
t/t3903-stash.sh
index 2fb651b2b8d9d91a130b1cbd11c3c2b6b1cf961b..e7b85932d6ba62ec9f581c692a321ac24e52dcac 100755 (executable)
@@ -19,6 +19,7 @@ OPTIONS_SPEC=
 START_DIR=$(pwd)
 . git-sh-setup
 require_work_tree
+prefix=$(git rev-parse --show-prefix) || exit 1
 cd_to_toplevel
 
 TMP="$GIT_DIR/.git-stash.$$"
@@ -273,6 +274,8 @@ push_stash () {
                shift
        done
 
+       eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
+
        if test -n "$patch_mode" && test -n "$untracked"
        then
                die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")"
index 3b4bed5c9ace3b9122380287c55b4130135018c7..4046817d70a0ac1dd5b11a49c500896688a4f0b1 100755 (executable)
@@ -812,6 +812,22 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
        test_path_is_file bar
 '
 
+test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
+       mkdir sub &&
+       >foo &&
+       >bar &&
+       git add foo bar &&
+       (
+               cd sub &&
+               git stash push -- ../foo
+       ) &&
+       test_path_is_file bar &&
+       test_path_is_missing foo &&
+       git stash pop &&
+       test_path_is_file foo &&
+       test_path_is_file bar
+'
+
 test_expect_success 'stash with multiple pathspec arguments' '
        >foo &&
        >bar &&