diff options
author | Øystein Walle <oystwa@gmail.com> | 2014-01-07 09:22:15 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-01-07 10:51:04 -0800 |
commit | 2a07e4374c0ba6f2e991965c99b448ccb563f2fc (patch) | |
tree | c05098f54001df66386863fda2062b7a2aceda02 | |
parent | c90d3dbe7db37f298e7ce858cfc4c494113f8945 (diff) | |
download | git-2a07e4374c0ba6f2e991965c99b448ccb563f2fc.tar.gz |
stash: handle specifying stashes with $IFSow/stash-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: Thomas Rast <tr@thomasrast.ch>
Signed-off-by: Øystein Walle <oystwa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | git-stash.sh | 14 | ||||
-rwxr-xr-x | t/t3903-stash.sh | 12 |
2 files changed, 19 insertions, 7 deletions
diff --git a/git-stash.sh b/git-stash.sh index 1e541a2125..f0a94abf14 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -358,7 +358,7 @@ parse_flags_and_rev() i_tree= u_tree= - REV=$(git rev-parse --no-flags --symbolic "$@") || exit 1 + REV=$(git rev-parse --no-flags --symbolic --sq "$@") || exit 1 FLAGS= for opt @@ -376,7 +376,7 @@ parse_flags_and_rev() esac done - set -- $REV + eval set -- $REV case $# in 0) @@ -391,13 +391,13 @@ parse_flags_and_rev() ;; 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" die "$(eval_gettext "\$reference is not valid reference")" } - 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) && + 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) && s=$1 && w_commit=$1 && b_commit=$2 && @@ -408,8 +408,8 @@ parse_flags_and_rev() test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" && IS_STASH_REF=t - u_commit=$(git rev-parse --quiet --verify $REV^3 2>/dev/null) && - u_tree=$(git rev-parse $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) } is_stash_like() diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index debda7a678..5b79b216e2 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -673,4 +673,16 @@ test_expect_success 'store updates stash ref and reflog' ' 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 |