All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git stash: Give friendlier error when there is nothing to apply
@ 2009-08-11 11:12 Ori Avtalion
  2009-08-11 12:09 ` Thomas Rast
  0 siblings, 1 reply; 7+ messages in thread
From: Ori Avtalion @ 2009-08-11 11:12 UTC (permalink / raw)
  To: git

The old message was scary and included a 'fatal' error from rev-parse:
     fatal: Needed a single revision
     : no valid stashed state found

The new message is identical to the one given by 'git stash branch', and
given *before* the check for a dirty working tree.

Previously, the command prompted the user to clean a dirty working tree
when there is nothing to apply.

Signed-off-by: Ori Avtalion <ori@avtalion.name>
---
 git-stash.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 03e589f..aa84144 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -162,6 +162,8 @@ show_stash () {
 }
 
 apply_stash () {
+	have_stash || die 'Nothing to apply'
+
 	git update-index -q --refresh &&
 	git diff-files --quiet --ignore-submodules ||
 		die 'Cannot apply to a dirty working tree, please stage your changes'
-- 
1.6.4.73.gc144.dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] git stash: Give friendlier errors when there is nothing to apply
  2009-08-11 12:09 ` Thomas Rast
@ 2009-08-11 11:12   ` Ori Avtalion
  2009-08-13  7:35     ` Thomas Rast
  2009-08-14 19:52     ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Ori Avtalion @ 2009-08-11 11:12 UTC (permalink / raw)
  To: git

The change makes sure a stash (given or default) exists before
checking if the working tree is dirty.

If the default stash is requested, the old message was scary and
included a 'fatal' error from rev-parse:
     fatal: Needed a single revision
     : no valid stashed state found

It is replaced with a friendlier 'Nothing to apply' error, similar to
'git stash branch'.

If a specific stash is specified, the 'Needed a single revision' errors
from rev-parse are suppressed.

Signed-off-by: Ori Avtalion <ori@avtalion.name>
---

Thomas, I added handling for the 'git stash apply <stash>' case based
on your reminder, and also changed the error messages related to it.

All of the stash tests pass, as before.

 git-stash.sh |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 03e589f..d61c9d0 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -162,10 +162,6 @@ show_stash () {
 }
 
 apply_stash () {
-	git update-index -q --refresh &&
-	git diff-files --quiet --ignore-submodules ||
-		die 'Cannot apply to a dirty working tree, please stage your changes'
-
 	unstash_index=
 
 	while test $# != 0
@@ -184,18 +180,27 @@ apply_stash () {
 		shift
 	done
 
-	# current index state
-	c_tree=$(git write-tree) ||
-		die 'Cannot apply a stash in the middle of a merge'
+	if test $# = 0
+	then
+		have_stash || die 'Nothing to apply'
+	fi
 
 	# stash records the work tree, and is a merge between the
 	# base commit (first parent) and the index tree (second parent).
-	s=$(git rev-parse --verify --default $ref_stash "$@") &&
-	w_tree=$(git rev-parse --verify "$s:") &&
-	b_tree=$(git rev-parse --verify "$s^1:") &&
-	i_tree=$(git rev-parse --verify "$s^2:") ||
+	s=$(git rev-parse --quiet --verify --default $ref_stash "$@") &&
+	w_tree=$(git rev-parse --quiet --verify "$s:") &&
+	b_tree=$(git rev-parse --quiet --verify "$s^1:") &&
+	i_tree=$(git rev-parse --quiet --verify "$s^2:") ||
 		die "$*: no valid stashed state found"
 
+	git update-index -q --refresh &&
+	git diff-files --quiet --ignore-submodules ||
+		die 'Cannot apply to a dirty working tree, please stage your changes'
+
+	# current index state
+	c_tree=$(git write-tree) ||
+		die 'Cannot apply a stash in the middle of a merge'
+
 	unstashed_index_tree=
 	if test -n "$unstash_index" && test "$b_tree" != "$i_tree" &&
 			test "$c_tree" != "$i_tree"
-- 
1.6.4.115.g82cf7

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] git stash: Give friendlier error when there is nothing to apply
  2009-08-11 11:12 [PATCH] git stash: Give friendlier error when there is nothing to apply Ori Avtalion
@ 2009-08-11 12:09 ` Thomas Rast
  2009-08-11 11:12   ` [PATCH] git stash: Give friendlier errors " Ori Avtalion
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Rast @ 2009-08-11 12:09 UTC (permalink / raw)
  To: Ori Avtalion; +Cc: git

Ori Avtalion wrote:
>  apply_stash () {
> +	have_stash || die 'Nothing to apply'
> +
>  	git update-index -q --refresh &&
>  	git diff-files --quiet --ignore-submodules ||
>  		die 'Cannot apply to a dirty working tree, please stage your changes'
> 

This needs a guard against the case where the user says

  git stash apply $some_sha1

but his refs/stash is empty.  This could be the case, e.g., after
mistakenly blowing away the reflog with 'git stash clear' and then
going on a recovery hunt through the unreferenced commits.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply
  2009-08-11 11:12   ` [PATCH] git stash: Give friendlier errors " Ori Avtalion
@ 2009-08-13  7:35     ` Thomas Rast
  2009-08-14 19:52     ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Rast @ 2009-08-13  7:35 UTC (permalink / raw)
  To: Ori Avtalion; +Cc: git

Ori Avtalion wrote:
> The change makes sure a stash (given or default) exists before
> checking if the working tree is dirty.
> 
> If the default stash is requested, the old message was scary and
> included a 'fatal' error from rev-parse:
>      fatal: Needed a single revision
>      : no valid stashed state found
> 
> It is replaced with a friendlier 'Nothing to apply' error, similar to
> 'git stash branch'.
> 
> If a specific stash is specified, the 'Needed a single revision' errors
> from rev-parse are suppressed.
> 
> Signed-off-by: Ori Avtalion <ori@avtalion.name>
> ---
> 
> Thomas, I added handling for the 'git stash apply <stash>' case based
> on your reminder, and also changed the error messages related to it.
> 
> All of the stash tests pass, as before.

Acked-by: Thomas Rast <trast@student.ethz.ch>

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply
  2009-08-11 11:12   ` [PATCH] git stash: Give friendlier errors " Ori Avtalion
  2009-08-13  7:35     ` Thomas Rast
@ 2009-08-14 19:52     ` Junio C Hamano
  2009-08-14 21:39       ` Nanako Shiraishi
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2009-08-14 19:52 UTC (permalink / raw)
  To: Nanako Shiraishi; +Cc: git, Ori Avtalion

Ori Avtalion <ori@avtalion.name> writes:

> The change makes sure a stash (given or default) exists before
> checking if the working tree is dirty.
>
> If the default stash is requested, the old message was scary and
> included a 'fatal' error from rev-parse:
>      fatal: Needed a single revision
>      : no valid stashed state found
>
> It is replaced with a friendlier 'Nothing to apply' error, similar to
> 'git stash branch'.
>
> If a specific stash is specified, the 'Needed a single revision' errors
> from rev-parse are suppressed.
>
> Signed-off-by: Ori Avtalion <ori@avtalion.name>
> Acked-by: Thomas Rast <trast@student.ethz.ch>

I do not see anything that might break existing usage of the command.
Comments?

A tangent; we might want an analogue to "shortlog -s -n" but based on
"blame".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply
  2009-08-14 19:52     ` Junio C Hamano
@ 2009-08-14 21:39       ` Nanako Shiraishi
  2009-08-15  1:50         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Nanako Shiraishi @ 2009-08-14 21:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Ori Avtalion

Quoting Junio C Hamano <gitster@pobox.com>

> Ori Avtalion <ori@avtalion.name> writes:
>
>> The change makes sure a stash (given or default) exists before
>> checking if the working tree is dirty.
>>
>> If the default stash is requested, the old message was scary and
>> included a 'fatal' error from rev-parse:
>>      fatal: Needed a single revision
>>      : no valid stashed state found
>>
>> It is replaced with a friendlier 'Nothing to apply' error, similar to
>> 'git stash branch'.
>>
>> If a specific stash is specified, the 'Needed a single revision' errors
>> from rev-parse are suppressed.
>>
>> Signed-off-by: Ori Avtalion <ori@avtalion.name>
>> Acked-by: Thomas Rast <trast@student.ethz.ch>
>
> I do not see anything that might break existing usage of the command.
> Comments?

The patch looks good to me. I think it was my fault but you can avoid 
adding two extra --quiet by inspecting i_tree (in other words, "$s^2:") 
before w_tree and b_tree. Because a commit that is a stash exactly has 
two parents, it may be good to also make sure 'git rev-parse "$s^3"' 
fails.

	s=$(git rev-parse --verify --default $ref_stash "$@") &&
	! git rev-parse --quiet --verify "$s^3" >/dev/null &&
	i_tree=$(git rev-parse --quiet --verify "$s^2:") &&
	b_tree=$(git rev-parse --verify "$s^1:") &&
	w_tree=$(git rev-parse --verify "$s:") ||
		die "$*: no valid stashed state found"

> A tangent; we might want an analogue to "shortlog -s -n" but based on
> "blame".

I'm sorry, I don't understand what you mean.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply
  2009-08-14 21:39       ` Nanako Shiraishi
@ 2009-08-15  1:50         ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2009-08-15  1:50 UTC (permalink / raw)
  To: Nanako Shiraishi; +Cc: git, Ori Avtalion

Nanako Shiraishi <nanako3@lavabit.com> writes:

> Quoting Junio C Hamano <gitster@pobox.com>
> ...
>> A tangent; we might want an analogue to "shortlog -s -n" but based on
>> "blame".
>
> I'm sorry, I don't understand what you mean.

I often use shortlog to find whom to CC to, but sometimes blame output
gives us a much better picture.

$ git shortlog -s -n git-stash.sh | head -n 6
    22	Junio C Hamano
     4	Brandon Casey
     2	Jeff King
     2	Johannes Schindelin
     2	Nanako Shiraishi
     2	SZEDER Gábor

$ git blame -w git-stash.sh |
  sed -e 's/^[0-9a-f]* (\(.*\) *200[7-9]-..-.. .*/\1/' |
  sort | uniq -c | sort -n -r | head -n 6
    110 Nanako Shiraishi    
     86 Junio C Hamano      
     55 Stephen Boyd        
     33 Brandon Casey       
     20 Abhijit Menon-Sen   
     16 Johannes Schindelin 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-08-15  1:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-11 11:12 [PATCH] git stash: Give friendlier error when there is nothing to apply Ori Avtalion
2009-08-11 12:09 ` Thomas Rast
2009-08-11 11:12   ` [PATCH] git stash: Give friendlier errors " Ori Avtalion
2009-08-13  7:35     ` Thomas Rast
2009-08-14 19:52     ` Junio C Hamano
2009-08-14 21:39       ` Nanako Shiraishi
2009-08-15  1:50         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.