Skip to content

Commit 49a8bf2

Browse files
committed
Merge branch 'ps/stash-push-pathspec-fix'
"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
2 parents b21d630 + 22fc703 commit 49a8bf2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

git-stash.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ OPTIONS_SPEC=
1919
START_DIR=$(pwd)
2020
. git-sh-setup
2121
require_work_tree
22+
prefix=$(git rev-parse --show-prefix) || exit 1
2223
cd_to_toplevel
2324

2425
TMP="$GIT_DIR/.git-stash.$$"
@@ -273,6 +274,8 @@ push_stash () {
273274
shift
274275
done
275276

277+
eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
278+
276279
if test -n "$patch_mode" && test -n "$untracked"
277280
then
278281
die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")"

t/t3903-stash.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,22 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
812812
test_path_is_file bar
813813
'
814814

815+
test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
816+
mkdir sub &&
817+
>foo &&
818+
>bar &&
819+
git add foo bar &&
820+
(
821+
cd sub &&
822+
git stash push -- ../foo
823+
) &&
824+
test_path_is_file bar &&
825+
test_path_is_missing foo &&
826+
git stash pop &&
827+
test_path_is_file foo &&
828+
test_path_is_file bar
829+
'
830+
815831
test_expect_success 'stash with multiple pathspec arguments' '
816832
>foo &&
817833
>bar &&

0 commit comments

Comments
 (0)