threads / patch / 8876

patchRe: [PATCH] stash: end commit log with a newline

Subject: Re: [PATCH] stash: end commit log with a newline

## tl;dr

4 messages between Jul 5, 2007 and Jul 5, 2007. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Junio C Hamano· Jul 5, 2007, 05:46 UTC · lore
しらいしななこ <nanako3@bluebottle.com> writes:
Show 14 quoted lines
> I am sorry to join the discussion late, but I think it is much better to let
> the user give a short reminder message from the command line.  For example,
>
>   $ git stash add customized message to stash
>
> When I say "git stash list", I want to see which branch I was on when I was
> in the middle of doing something, and what that something was.  It is not
> interesting which commit on that branch I started that change from.  After
> creating a stash without a message, and then another stash with a message, I
> want to see:
>
>   $ git stash list
>   stash@{0}: On master: add customized message to stash
>   stash@{1}: WIP on master: 36e5e70... Start deprecating "git-command" in favor of "git command"

Hmph. I only recently got interested in "stash", so have not enough real-life experience to base my judgement on, but I think I'd agree with your reasoning.

Perhaps something like this?

-- >8 -- [PATCH] git-stash: allow more descriptive reminder message when saving

This allows you to say:
	$ git stash starting to implement X

while creating a stash, and the resulting "stash list entry would read as:

	$ git stash list
        stash@{0}: On master: starting to implement X

instead of the default message which talks about the commit the stash happens to be based on (hence does not have much to do with what the stashed change is trying to do).

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 git-stash.sh |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)
Show changes to git-stash.sh +19 −6
diff --git a/git-stash.sh b/git-stash.sh
index 9deda44..3d7db4a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -23,6 +23,8 @@ clear_stash () {
 }
 
 save_stash () {
+	stash_msg="$1"
+
 	if no_changes
 	then
 		echo >&2 'No local changes to save'
@@ -67,13 +69,19 @@ save_stash () {
 		die "Cannot save the current worktree state"
 
 	# create the stash
-	w_commit=$(printf 'WIP on %s\n' "$msg" |
+	if test -z "$stash_msg"
+	then
+		stash_msg=$(printf 'WIP on %s' "$msg")
+	else
+		stash_msg=$(printf 'On %s: %s' "$branch" "$stash_msg")
+	fi
+	w_commit=$(printf '%s\n' "$stash_msg" |
 		git commit-tree $w_tree -p $b_commit -p $i_commit) ||
 		die "Cannot record working tree state"
 
-	git update-ref -m "$msg" $ref_stash $w_commit ||
+	git update-ref -m "$stash_msg" $ref_stash $w_commit ||
 		die "Cannot save the current status"
-	printf >&2 'Saved WIP on %s\n' "$msg"
+	printf >&2 'Saved "%s"\n' "$stash_msg"
 }
 
 have_stash () {
@@ -157,9 +165,14 @@ apply)
 clear)
 	clear_stash
 	;;
-save | '')
-	save_stash && git-reset --hard
+help)
+	usage
 	;;
 *)
-	usage
+	if test $# -gt 0 && test "$1" = save
+	then
+		shift
+	fi
+	save_stash "$*" && git-reset --hard
+	;;
 esac
-- 
Junio C Hamano
http://gitster.livejournal.com/

----------------------------------------------------------------------
No advertising message here ;-)
http://www.ohloh.net/projects/278
Uwe Kleine-König· Jul 5, 2007, 11:58 UTC · re: Junio C Hamano · lore
Junio C Hamano wrote:
Show 22 quoted lines
> しらいしななこ <nanako3@bluebottle.com> writes:
> 
> > I am sorry to join the discussion late, but I think it is much better to let
> > the user give a short reminder message from the command line.  For example,
> >
> >   $ git stash add customized message to stash
> >
> > When I say "git stash list", I want to see which branch I was on when I was
> > in the middle of doing something, and what that something was.  It is not
> > interesting which commit on that branch I started that change from.  After
> > creating a stash without a message, and then another stash with a message, I
> > want to see:
> >
> >   $ git stash list
> >   stash@{0}: On master: add customized message to stash
> >   stash@{1}: WIP on master: 36e5e70... Start deprecating "git-command" in favor of "git command"
> 
> Hmph.  I only recently got interested in "stash", so have not
> enough real-life experience to base my judgement on, but I think
> I'd agree with your reasoning.
> 
> Perhaps something like this?

I didn't test it yet, but it sounds good. I will apply your patch and work a while with it. But I think if someone adds documentation, I will give my Ack. :-)

BTW: I prefer help over usage, but if it nanako prefers usage, why not
both?

Best regards Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=1+stone%3D
Junio C Hamano· Jul 5, 2007, 16:47 UTC · re: Uwe Kleine-König · lore
Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:
Show 6 quoted lines
> I didn't test it yet, but it sounds good.  I will apply your patch and
> work a while with it.  But I think if someone adds documentation, I will
> give my Ack. :-)
>
> BTW: I prefer help over usage, but if it nanako prefers usage, why not
> both?
We could do that, I guess.  Nana?
しらいしななこ· Jul 5, 2007, 23:54 UTC · re: Junio C Hamano · lore
Quoting Junio C Hamano <gitster@pobox.com>:
Show 10 quoted lines
> Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:
>
>> I didn't test it yet, but it sounds good.  I will apply your patch and
>> work a while with it.  But I think if someone adds documentation, I will
>> give my Ack. :-)
>>
>> BTW: I prefer help over usage, but if it nanako prefers usage, why not
>> both?
>
> We could do that, I guess.  Nana?
Thank you very much for asking.

I think it is good to accept both usage and help, then. I will try your patch myself and will report if I can think of further improvements.

Please do not expect much documentation from me, however. My writing is not very good.

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

----------------------------------------------------------------------
Find out how you can get spam free email.
http://www.bluebottle.com/tag/3

← back to recent threads