提交 2a07e437 编写于 作者: Ø Øystein Walle 提交者: Junio C Hamano

stash: handle specifying stashes with $IFS

When trying to pop/apply a stash specified with an argument
containing IFS whitespace, git-stash will throw an error:

    $ git stash pop 'stash@{two hours ago}'
    Too many revisions specified: stash@{two hours ago}

This happens because word splitting is used to count non-option
arguments. Make use of rev-parse's --sq option to quote the arguments
for us to ensure a correct count. Add quotes where necessary.

Also add a test that verifies correct behaviour.
Helped-by: NThomas Rast <tr@thomasrast.ch>
Signed-off-by: NØystein Walle <oystwa@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 c90d3dbe
...@@ -358,7 +358,7 @@ parse_flags_and_rev() ...@@ -358,7 +358,7 @@ parse_flags_and_rev()
i_tree= i_tree=
u_tree= u_tree=
REV=$(git rev-parse --no-flags --symbolic "$@") || exit 1 REV=$(git rev-parse --no-flags --symbolic --sq "$@") || exit 1
FLAGS= FLAGS=
for opt for opt
...@@ -376,7 +376,7 @@ parse_flags_and_rev() ...@@ -376,7 +376,7 @@ parse_flags_and_rev()
esac esac
done done
set -- $REV eval set -- $REV
case $# in case $# in
0) 0)
...@@ -391,13 +391,13 @@ parse_flags_and_rev() ...@@ -391,13 +391,13 @@ parse_flags_and_rev()
;; ;;
esac esac
REV=$(git rev-parse --quiet --symbolic --verify $1 2>/dev/null) || { REV=$(git rev-parse --quiet --symbolic --verify "$1" 2>/dev/null) || {
reference="$1" reference="$1"
die "$(eval_gettext "\$reference is not valid reference")" die "$(eval_gettext "\$reference is not valid reference")"
} }
i_commit=$(git rev-parse --quiet --verify $REV^2 2>/dev/null) && i_commit=$(git rev-parse --quiet --verify "$REV^2" 2>/dev/null) &&
set -- $(git rev-parse $REV $REV^1 $REV: $REV^1: $REV^2: 2>/dev/null) && set -- $(git rev-parse "$REV" "$REV^1" "$REV:" "$REV^1:" "$REV^2:" 2>/dev/null) &&
s=$1 && s=$1 &&
w_commit=$1 && w_commit=$1 &&
b_commit=$2 && b_commit=$2 &&
...@@ -408,8 +408,8 @@ parse_flags_and_rev() ...@@ -408,8 +408,8 @@ parse_flags_and_rev()
test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" && test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
IS_STASH_REF=t IS_STASH_REF=t
u_commit=$(git rev-parse --quiet --verify $REV^3 2>/dev/null) && u_commit=$(git rev-parse --quiet --verify "$REV^3" 2>/dev/null) &&
u_tree=$(git rev-parse $REV^3: 2>/dev/null) u_tree=$(git rev-parse "$REV^3:" 2>/dev/null)
} }
is_stash_like() is_stash_like()
......
...@@ -673,4 +673,16 @@ test_expect_success 'store updates stash ref and reflog' ' ...@@ -673,4 +673,16 @@ test_expect_success 'store updates stash ref and reflog' '
grep quux bazzy grep quux bazzy
' '
test_expect_success 'handle stash specification with spaces' '
git stash clear &&
echo pig >file &&
git stash &&
stamp=$(git log -g --format="%cd" -1 refs/stash) &&
test_tick &&
echo cow >file &&
git stash &&
git stash apply "stash@{$stamp}" &&
grep pig file
'
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册