git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] Improve error messages from 'git stash show'

From
Gustaf Hendeby <hendeby@isy.liu.se>
Date
Mar 16, 2010, 17:52 UTC
Message-ID
<1268761957-9769-1-git-send-email-hendeby@isy.liu.se>
In-Reply-To
<7v4okgfbrt.fsf@alter.siamese.dyndns.org>

The previous error message "fatal: Needed a single revision" is not very informative.

Signed-off-by: Gustaf Hendeby <hendeby@isy.liu.se>
---
On 03/16/2010 05:53 PM, Junio C Hamano wrote:
Show 13 quoted lines
>>>> +	b_commit=$(git rev-parse --quiet --verify "$w_commit^") ||
>>>> >>>  +		die 'Stash not found'
>>>> >>>  +
>>> >>  
>>> >>  Because you checked have_stash upfront, an error detected here cannot be
>>> >>  "stash not found".  It is something else, isn't it?
>> >
>> >  This case occurs when you do something like git stash foo, where foo is
>> >  no appropriate stash to show.  Would something like this be more
>> >  informative in the case of git stash foo:
>> >
>> >  Stash entry 'foo' could not be found
> That is more like "'foo' is not a stash", isn't it?
I find your suggestion much clearer.  Thank you!
/Gustaf
 git-stash.sh |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index aa47e54..59db3dc 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -210,14 +210,18 @@ list_stash () {
 }
 
 show_stash () {
+	have_stash || die 'No stash found'
+
 	flags=$(git rev-parse --no-revs --flags "$@")
 	if test -z "$flags"
 	then
 		flags=--stat
 	fi
 
-	w_commit=$(git rev-parse --verify --default $ref_stash "$@") &&
-	b_commit=$(git rev-parse --verify "$w_commit^") &&
+	w_commit=$(git rev-parse --quiet --verify --default $ref_stash "$@") &&
+	b_commit=$(git rev-parse --quiet --verify "$w_commit^") ||
+		die "'$*' is not a stash"
+
 	git diff $flags $b_commit $w_commit
 }
 
-- 
1.7.0.2.274.gba5d.dirty
Previous: Junio C Hamano
Message 5 of 5 in “Improve error messages from 'git stash show'”
  1. 1/1 Improve error messages from 'git stash show'Gustaf Hendeby, Mar 15, 2010
  2. Junio C HamanoMar 15, 2010
  3. Gustaf HendebyMar 16, 2010
  4. Junio C HamanoMar 16, 2010
  5. Improve error messages from 'git stash show'Gustaf Hendeby, Mar 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.