*** SUBJECT HERE ***
v2 cover *** SUBJECT HERE ***
This series fixes git stash branch so that it is more tolerant of stash-like commits created with git stash create.
It particular, it doesn't require there to be a stash stack if a stash-like argument is specified and it doesn't attempt to drop non-stash references after applying the stash.
This series replaces my previous patch that just included a test that demonstrated the existance of the issue.
stash: It looks like a stash, but doesn't quack like a stash...
stash: Allow git stash branch to process commits that look like
stashes but are not stash references.
stash: modify tests to reflect stash branch fixes.
git-stash.sh | 10 ++++++++-- t/t3903-stash.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.2.1.111.g8fc90
PATCH v2 1/3 stash: It looks like a stash, but doesn't quack like a stash...
In particular, a stash created with git stash create cannot be used as an argument to git stash branch because of two separate reasons.
1. a pre-condition assumes that there is always a stash on the stack when git stash branch is called, which is not necessarily true
2. the cleanup code assumes the specified stash is a stash reference, rather than an arbitrary commit.
The test_expect_failure tests in this patch demonstrate these issues.
--- t/t3903-stash.sh | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
t/t3903-stash.sh +30 -0
@@ -378,4 +378,34 @@ test_expect_failure 'stash file to directory' ' test foo = "$(cat file/file)" ' +test_expect_failure 'stash branch from arbitrary stash ref when there are no stash references' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + git reset --hard && + echo foo >> file && + git tag stash-tag $(git stash create) && + test_when_finished "git tag -d stash-tag" && + git reset --hard && + git stash branch stash-branch $(git rev-parse stash-tag) && + test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" && + test $(git ls-files --modified | wc -l) -eq 1 +' + +test_expect_failure 'stash branch from arbitrary stash ref fails even if there is a stash' ' + git stash clear && { + git branch -D stash-branch || true + } + test_when_finished "git reset --hard HEAD" && + git reset --hard && + echo foo >> file && + git stash && + echo bar >> file && + git tag stash-tag $(git stash create) && + test_when_finished "git tag -d stash-tag" && + git reset --hard && + git stash branch stash-branch $(git rev-parse stash-tag) && + test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" && + test $(git ls-files --modified | wc -l) -eq 1 +' + test_done
Signature · 1 line
1.7.2.1.111.g8fc90
Re: [PATCH v2 1/3] stash: It looks like a stash, but doesn't quack like a stash...
Quoted 7 lines · Jon Seymour
In particular, a stash created with git stash create cannot be used as an argument to git stash branch because of two separate reasons.
1. a pre-condition assumes that there is always a stash on the stack when git stash branch is called, which is not necessarily true
2. the cleanup code assumes the specified stash is a stash reference, rather than an arbitrary commit.
Hmm, I don't use the command myself so I ended up reading the description of "stash branch". To me it is clear that it wants to use a stash entry, not just an arbitrary stash-looking commit, from "... then drops the <stash>".
So I wouldn't call these tests "expect-failure"; rather, I would suggest swapping the order of patches so that they test the new feature that allows "git stash branch" to take an arbitrary stash-looking commit.
The documentation also needs to be updated to make the "then drops" part conditional (perhaps "then drops...if the stash was on the list").
Are there any other stash subcommand that ought to be able to act on a stash-looking commit but doesn't, or is "branch" the only one?
PATCH v2 2/3 stash: Allow git stash branch to process commits that look like stashes but are not stash references.
In reply to Jon SeymourThis patch allows git stash branch to work with stash-like commits created by git stash create.
Two changes were required:
* relax the pre-condition so that a stash stack is required if and only if a stash argument is not specified
* don't attempt to drop a stash argument that doesn't look like a stash reference.
--- git-stash.sh | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
git-stash.sh +8 -2
@@ -225,6 +225,12 @@ show_stash () { git diff $flags $b_commit $w_commit } +if_stash_ref() { + ref="$1" + shift + test "${ref#stash}" = "${ref}" -a "${ref#$ref_stash}" = "${ref}" || "$@" +} + apply_stash () { applied_stash= unstash_index=
@@ -359,20 +365,20 @@ drop_stash () { } apply_to_branch () { - have_stash || die 'Nothing to apply' test -n "$1" || die 'No branch name specified' branch=$1 if test -z "$2" then + have_stash || die 'Nothing to apply' set x "$ref_stash@{0}" fi stash=$2 git checkout -b $branch $stash^ && apply_stash --index $stash && - drop_stash $stash + if_stash_ref "$stash" drop_stash "$stash" } # The default command is "save" if nothing but options are given
Signature · 1 line
1.7.2.1.111.g8fc90
PATCH v2 3/3 stash: modify tests to reflect stash branch fixes.
In reply to Jon SeymourThese tests now pass so they are now updated to reflect this.
--- t/t3903-stash.sh | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
t/t3903-stash.sh +3 -5
@@ -378,7 +378,7 @@ test_expect_failure 'stash file to directory' ' test foo = "$(cat file/file)" ' -test_expect_failure 'stash branch from arbitrary stash ref when there are no stash references' ' +test_expect_success 'stash branch with no stashes on stack and stash-like reference as argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard &&
@@ -391,10 +391,8 @@ test_expect_failure 'stash branch from arbitrary stash ref when there are no sta test $(git ls-files --modified | wc -l) -eq 1 ' -test_expect_failure 'stash branch from arbitrary stash ref fails even if there is a stash' ' - git stash clear && { - git branch -D stash-branch || true - } +test_expect_success 'stash branch with stashes on stack and stash-like reference as argument' ' + git stash clear && test_when_finished "git reset --hard HEAD" && git reset --hard && echo foo >> file &&
Signature · 1 line
1.7.2.1.111.g8fc90
Re: [PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references.
In reply to Jon SeymourQuoted 9 lines · Jon Seymour
This patch allows git stash branch to work with stash-like commits created by git stash create.
Two changes were required:
* relax the pre-condition so that a stash stack is required if and only if a stash argument is not specified
* don't attempt to drop a stash argument that doesn't look like a stash reference.Signed-off-by Jon Seymour <[email protected]>
Please wrap very long lines.
git-stash.sh show_stash () { · line 232
Quoted 13 lines
git-stash.sh +5
-0@@ -225,6 +225,12 @@ show_stash () { git diff $flags $b_commit $w_commit } +if_stash_ref() { + ref="$1" + shift + test "${ref#stash}" = "${ref}" -a "${ref#$ref_stash}" = "${ref}" || "$@" +}
The interface to this function looks a rather bad taste to me; wouldn't it look more natural if the callers can say:
if stash_ref $it
then
do this
fi
Your criteria used here is that the given parameter does not begin with "stash" nor "refs/stash". If it begins with either of these two strings, the "test" fails and "$@" is run. Wouldn't this produce a false hit if you kept a handcrafted stash-looking commit with a tag "stash-42" or something?
It may make more sense to give "stash drop" an option to be silent if the given parameter is not on the list to begin with, perhaps?
Re: [PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references.
Junio,
Thanks for the feedback. I'll rework along the lines you suggest. If it makes sense to make the other stash commands tolerant of non-stash entry references I'll add tests, support and documentation for that.
jon.
Quoted 46 lines · Junio C Hamano
Quoted 9 lines · Jon Seymour
This patch allows git stash branch to work with stash-like commits created by git stash create.
Two changes were required:
* relax the pre-condition so that a stash stack is required if and only if a stash argument is not specified
* don't attempt to drop a stash argument that doesn't look like a stash reference.Signed-off-by Jon Seymour <[email protected]>Please wrap very long lines.
git-stash.sh show_stash () { · line 232
Quoted 13 lines
git-stash.sh +0
-0@@ -225,6 +225,12 @@ show_stash () {git diff $flags $b_commit $w_commit
}git-stash.sh +5
-0+if_stash_ref() { + ref="$1" + shift + test "${ref#stash}" = "${ref}" -a "${ref#$ref_stash}" = "${ref}" || "$@" +}The interface to this function looks a rather bad taste to me; wouldn't it look more natural if the callers can say:
if
stash_ref$it
then
do this
fiYour criteria used here is that the given parameter does not begin with "stash" nor "refs/stash". If it begins with either of these two strings, the "test" fails and "$@" is run. Wouldn't this produce a false hit if you kept a handcrafted stash-looking commit with a tag "stash-42" or something?
It may make more sense to give "stash drop" an option to be silent if the given parameter is not on the list to begin with, perhaps?
Re: [PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references.
One question about test patches. Are you ok with test_expect_failure tests that document the expected failure of a feature yet to be developed, followed by the feature, followed by the patch that makes the tests into test_expect_success tests, or would you prefer to see the pre- and post- test patches rolled into a single test that is delivered after the feature patch?
Quoted 56 lines · Jon Seymour
Junio,
Thanks for the feedback. I'll rework along the lines you suggest. If it makes sense to make the other stash commands tolerant of non-stash entry references I'll add tests, support and documentation for that.
jon.
Quoted 46 lines · Junio C Hamano
Quoted 9 lines · Jon Seymour
This patch allows git stash branch to work with stash-like commits created by git stash create.
Two changes were required:
* relax the pre-condition so that a stash stack is required if and only if a stash argument is not specified
* don't attempt to drop a stash argument that doesn't look like a stash reference.Signed-off-by Jon Seymour <[email protected]>Please wrap very long lines.
git-stash.sh show_stash () { · line 232
Quoted 13 lines
git-stash.sh +0
-0@@ -225,6 +225,12 @@ show_stash () {git diff $flags $b_commit $w_commit
}git-stash.sh +5
-0+if_stash_ref() { + ref="$1" + shift + test "${ref#stash}" = "${ref}" -a "${ref#$ref_stash}" = "${ref}" || "$@" +}The interface to this function looks a rather bad taste to me; wouldn't it look more natural if the callers can say:
if
stash_ref$it
then
do this
fiYour criteria used here is that the given parameter does not begin with "stash" nor "refs/stash". If it begins with either of these two strings, the "test" fails and "$@" is run. Wouldn't this produce a false hit if you kept a handcrafted stash-looking commit with a tag "stash-42" or something?
It may make more sense to give "stash drop" an option to be silent if the given parameter is not on the list to begin with, perhaps?
Re: [PATCH v2 2/3] stash: Allow git stash branch to process commits that look like stashes but are not stash references.
Quoted 6 lines · Jon Seymour
One question about test patches. Are you ok with
test_expect_failuretests that document the expected failure of a feature yet to be developed, followed by the feature, followed by the patch that makes the tests intotest_expect_successtests, or would you prefer to see the pre- and post- test patches rolled into a single test that is delivered after the feature patch?
I think a single patch that implements the feature and at the same time protects it with new tests from getting broken by others would be the best form.