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

[PATCH] stash: Fix multiple error messages on create if no HEAD

From
Sebastian Morr <sebastian@morr.cc>
Date
Dec 14, 2011, 00:14 UTC
Message-ID
<20111214001432.GA2959@thinkpad>

create_stash() checks whether HEAD is valid via rev-parse. If this is not the case, both itself as well as rev-parse print an error message. Make rev-parse quiet.

In no_changes(), diff-index is called, which dies unquietly if there is no commit. Hide it's stderr.

Signed-off-by: Sebastian Morr <sebastian@morr.cc>
---
This bugged me: In a new, empty repository:
    $ git stash
    fatal: bad revision 'HEAD'
    fatal: bad revision 'HEAD'
    fatal: Needed a single revision
    You do not have the initial commit yet
With this patch:
    $ git stash
    You do not have the initial commit yet

With the --quiet option, I wouldn't expect diff-index to print error messages. But it does so (via revision.c, setup_revisions()). Is this wanted?

 git-stash.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index c766692..07b6511 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -34,7 +34,7 @@ else
 fi
 
 no_changes () {
-	git diff-index --quiet --cached HEAD --ignore-submodules -- &&
+	git diff-index --quiet --cached HEAD --ignore-submodules -- 2>/dev/null &&
 	git diff-files --quiet --ignore-submodules &&
 	(test -z "$untracked" || test -z "$(untracked_files)")
 }
@@ -67,7 +67,7 @@ create_stash () {
 	fi
 
 	# state of the base commit
-	if b_commit=$(git rev-parse --verify HEAD)
+	if b_commit=$(git rev-parse --quiet --verify HEAD)
 	then
 		head=$(git rev-list --oneline -n 1 HEAD --)
 	else
-- 
1.7.8.168.gd6118.dirty
Next: Junio C Hamano
Message 1 of 2 in “stash: Fix multiple error messages on create if no HEAD”
  1. stash: Fix multiple error messages on create if no HEADSebastian Morr, Dec 14, 2011
  2. Junio C HamanoDec 14, 2011

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.