Hi,
So, I've taken Junio's suggestion and designed a proper command-line
interface for 'git stash store' in this iteration:
git stash store [-m <message>] [-e <error>] <commit>
The error string will be passed through eval_gettext before it is
printed. Otherwise, the idea is the same: to clean up the logic
surrounding autostash.
Thanks.
Ramkumar Ramachandra (5):
stash doc: add a warning about using create
stash doc: document short form -p in synopsis
stash: simplify option parser for create
stash: introduce 'git stash store'
rebase: use 'git stash store' to simplify logic
Documentation/git-stash.txt | 12 ++++++++--
git-rebase.sh | 6 +----
git-stash.sh | 53 ++++++++++++++++++++++++++++++++++++---------
t/t3903-stash.sh | 19 ++++++++++++++++
4 files changed, 73 insertions(+), 17 deletions(-)
--
1.8.3.1.383.g0d5ad6b
Add a note saying that the user probably wants "save" in the create
description. While at it, document that it can optionally take a
message in the synopsis.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
Documentation/git-stash.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -151,6 +151,7 @@ create:: Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace.+ This is probably not what you want to use; see "save" above. DISCUSSION
'git stash save' can take -p, the short form of --patch, as an option.
Document this.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
Documentation/git-stash.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rebase has no reason to know about the implementation of the stash. In
the case when applying the autostash results in conflicts, replace the
relevant code in finish_rebase () to simply call 'git stash store'.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
git-rebase.sh | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
save_stash() contains the logic for doing two potentially independent
operations; the first is preparing the stash merge commit, and the
second is updating the stash ref/ reflog accordingly. While the first
operation is abstracted out into a create_stash() for callers to access
via 'git stash create', the second one is not. Fix this by factoring
out the logic for storing the stash into a store_stash() that callers
can access via 'git stash store'.
Like create, store is not intended for end user interactive use, but for
callers in other scripts. We can simplify the logic in the
rebase.autostash feature using this new subcommand.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
Documentation/git-stash.txt | 7 +++++++
git-stash.sh | 48 +++++++++++++++++++++++++++++++++++++++------
t/t3903-stash.sh | 19 ++++++++++++++++++
3 files changed, 68 insertions(+), 6 deletions(-)
@@ -153,6 +154,12 @@ create:: object name, without storing it anywhere in the ref namespace. This is probably not what you want to use; see "save" above.+store::++ Store a given stash created via 'git stash create' (which is a+ dangling merge commit) in the stash ref, updating the stash+ reflog. This is probably not what you want to use; see+ "save" above. DISCUSSION ----------
@@ -156,6 +156,43 @@ create_stash () {die"$(gettext"Cannot record working tree state")"}+store_stash(){+whiletest$#!=0+do+case"$1"in+-m|--message)+shift+stash_msg="$1"+;;+-e|--error)+shift+error_msg="$1"+;;+*)+break+;;+esac+shift+done+test$#==1||+die"$(eval_gettext"\"$dashless store\" requires one <commit> argument")"++w_commit="$1"+iftest-z"$stash_msg"+then+stash_msg="Created via \"git stash store\"."+fi+iftest-z"$error_msg"+then+error_msg="Cannot update $ref_stash with $w_commit."+fi++# Make sure the reflog for stash is kept.+:>>"$GIT_DIR/logs/$ref_stash"+gitupdate-ref-m"$stash_msg"$ref_stash$w_commit||+die"$(eval_gettext"$error_msg")"+}+ save_stash(){keep_index=patch_mode=
@@ -227,12 +264,7 @@ save_stash () {clear_stash||die"$(gettext"Cannot initialize stash")"create_stash"$stash_msg"$untracked--# Make sure the reflog for stash is kept.-:>>"$GIT_DIR/logs/$ref_stash"--gitupdate-ref-m"$stash_msg"$ref_stash$w_commit||-die"$(gettext"Cannot save the current status")"+store_stash-m"$stash_msg"-e"Cannot save the current status."$w_commitsaySavedworkingdirectoryandindexstate"$stash_msg"iftest-z"$patch_mode"
@@ -637,4 +637,23 @@ test_expect_success 'stash where working directory contains "HEAD" file' 'test_cmpoutputexpect'+test_expect_success'store called with invalid commit''+test_must_failgitstashstorefoo+'++test_expect_success'store updates stash ref and reflog''+gitstashclear&&+gitreset--hard&&+echoquux>bazzy&&+gitaddbazzy&&+STASH_ID=$(gitstashcreate)&&+gitreset--hard&&+!grepquuxbazzy&&+gitstashstore-mquuxery$STASH_ID&&+test$(cat.git/refs/stash)=$STASH_ID&&+grep$STASH_ID.git/logs/refs/stash&&+gitstashpop&&+grepquuxbazzy+'+ test_done
The option parser for create unnecessarily checks "$1" inside a case
statement that matches "$1" in the first place.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
git-stash.sh | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
From: Phil Hord <hidden> Date: 2016-06-15 22:57:44
On Fri, Jun 14, 2013 at 6:32 AM, Ramkumar Ramachandra
[off-list ref] wrote:
quoted hunk
Add a note saying that the user probably wants "save" in the create
description. While at it, document that it can optionally take a
message in the synopsis.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
Documentation/git-stash.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -151,6 +151,7 @@ create:: Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace.+ This is probably not what you want to use; see "save" above.
Thanks, this is helpful.
Maybe you can also hint why this command exists.
+ This is intended to be useful for scripts. It is probably not the
+ command you want to use; see "save" above.
DISCUSSION
--
1.8.3.1.383.g0d5ad6b
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Phil Hord <hidden> Date: 2016-06-15 22:57:44
On Fri, Jun 14, 2013 at 6:32 AM, Ramkumar Ramachandra
[off-list ref] wrote:
quoted hunk
save_stash() contains the logic for doing two potentially independent
operations; the first is preparing the stash merge commit, and the
second is updating the stash ref/ reflog accordingly. While the first
operation is abstracted out into a create_stash() for callers to access
via 'git stash create', the second one is not. Fix this by factoring
out the logic for storing the stash into a store_stash() that callers
can access via 'git stash store'.
Like create, store is not intended for end user interactive use, but for
callers in other scripts. We can simplify the logic in the
rebase.autostash feature using this new subcommand.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
Documentation/git-stash.txt | 7 +++++++
git-stash.sh | 48 +++++++++++++++++++++++++++++++++++++++------
t/t3903-stash.sh | 19 ++++++++++++++++++
3 files changed, 68 insertions(+), 6 deletions(-)
@@ -153,6 +154,12 @@ create:: object name, without storing it anywhere in the ref namespace. This is probably not what you want to use; see "save" above.+store::++ Store a given stash created via 'git stash create' (which is a+ dangling merge commit) in the stash ref, updating the stash+ reflog. This is probably not what you want to use; see+ "save" above.
Here, again, I think you should explain more about this command. Your
commit message explained it pretty well.
+ Like create, store is intended to be useful for scripts.
@@ -156,6 +156,43 @@ create_stash () {die"$(gettext"Cannot record working tree state")"}+store_stash(){+whiletest$#!=0+do+case"$1"in+-m|--message)+shift+stash_msg="$1"+;;+-e|--error)+shift+error_msg="$1"+;;+*)+break+;;+esac+shift+done+test$#==1||+die"$(eval_gettext"\"$dashless store\" requires one <commit> argument")"++w_commit="$1"+iftest-z"$stash_msg"+then+stash_msg="Created via \"git stash store\"."+fi+iftest-z"$error_msg"+then+error_msg="Cannot update $ref_stash with $w_commit."+fi++# Make sure the reflog for stash is kept.+:>>"$GIT_DIR/logs/$ref_stash"+gitupdate-ref-m"$stash_msg"$ref_stash$w_commit||+die"$(eval_gettext"$error_msg")"+}+ save_stash(){keep_index=patch_mode=
@@ -227,12 +264,7 @@ save_stash () {clear_stash||die"$(gettext"Cannot initialize stash")"create_stash"$stash_msg"$untracked--# Make sure the reflog for stash is kept.-:>>"$GIT_DIR/logs/$ref_stash"--gitupdate-ref-m"$stash_msg"$ref_stash$w_commit||-die"$(gettext"Cannot save the current status")"+store_stash-m"$stash_msg"-e"Cannot save the current status."$w_commit
nit: this adds a period to the end of the message which it did not
have previously.
quoted hunk
say Saved working directory and index state "$stash_msg"
if test -z "$patch_mode"
@@ -637,4 +637,23 @@ test_expect_success 'stash where working directory contains "HEAD" file' 'test_cmpoutputexpect'+test_expect_success'store called with invalid commit''+test_must_failgitstashstorefoo+'++test_expect_success'store updates stash ref and reflog''+gitstashclear&&+gitreset--hard&&+echoquux>bazzy&&+gitaddbazzy&&+STASH_ID=$(gitstashcreate)&&+gitreset--hard&&+!grepquuxbazzy&&+gitstashstore-mquuxery$STASH_ID&&+test$(cat.git/refs/stash)=$STASH_ID&&+grep$STASH_ID.git/logs/refs/stash&&+gitstashpop&&+grepquuxbazzy+'+ test_done--
From: Phil Hord <hidden> Date: 2016-06-15 22:57:44
On Fri, Jun 14, 2013 at 6:32 AM, Ramkumar Ramachandra
[off-list ref] wrote:
quoted hunk
rebase has no reason to know about the implementation of the stash. In
the case when applying the autostash results in conflicts, replace the
relevant code in finish_rebase () to simply call 'git stash store'.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
git-rebase.sh | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
@@ -153,11 +153,7 @@ finish_rebase () {thenecho"$(gettext'Applied autostash.')"else-ref_stash=refs/stash&&->>"$GIT_DIR/logs/$ref_stash"&&-gitupdate-ref-m"autostash"$ref_stash$stash_sha1||-die"$(eval_gettext'Cannot store $stash_sha1')"-+gitstashstore-m"autostash"-e"Cannot store $stash_sha1."$stash_sha1
nit: adds a period where there was not one previously.
Maybe this doesn't matter so much since this code is new anyway. But
showing a period after sha1 seems wrong, too. Or maybe I am confused
again. Does eval_gettext routinely add a period to the end of
translated strings?
gettext 'Applying autostash resulted in conflicts.
Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" it at any time.
--
1.8.3.1.383.g0d5ad6b
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html