{"thread":{"id":"29158","subject":"[PATCH] stash: Fix multiple error messages on create if no HEAD","startedAt":"2011-12-14T00:14:32Z","lastAt":"2011-12-14T01:16:26Z","messageCount":2,"participants":["Sebastian Morr","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"181102","messageId":"20111214001432.GA2959@thinkpad","threadId":"29158","inReplyTo":null,"subject":"[PATCH] stash: Fix multiple error messages on create if no HEAD","fromName":"Sebastian Morr","fromEmail":"sebastian@morr.cc","sentAt":"2011-12-14T00:14:32Z","receivedAt":"2011-12-14T00:14:32Z","isPatch":true,"sender":{"key":"sebastian@morr.cc","avatar":"https://avatars.githubusercontent.com/u/81277?v=4"},"body":"create_stash() checks whether HEAD is valid via rev-parse. If this is\nnot the case, both itself as well as rev-parse print an error message.\nMake rev-parse quiet.\n\nIn no_changes(), diff-index is called, which dies unquietly if there is\nno commit. Hide it's stderr.\n\nSigned-off-by: Sebastian Morr <sebastian@morr.cc>\n---\n\nThis bugged me: In a new, empty repository:\n\n    $ git stash\n    fatal: bad revision 'HEAD'\n    fatal: bad revision 'HEAD'\n    fatal: Needed a single revision\n    You do not have the initial commit yet\n\nWith this patch:\n\n    $ git stash\n    You do not have the initial commit yet\n\nWith the --quiet option, I wouldn't expect diff-index to print error\nmessages. But it does so (via revision.c, setup_revisions()). Is this\nwanted?\n\n git-stash.sh |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex c766692..07b6511 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -34,7 +34,7 @@ else\n fi\n \n no_changes () {\n-\tgit diff-index --quiet --cached HEAD --ignore-submodules -- &&\n+\tgit diff-index --quiet --cached HEAD --ignore-submodules -- 2>/dev/null &&\n \tgit diff-files --quiet --ignore-submodules &&\n \t(test -z \"$untracked\" || test -z \"$(untracked_files)\")\n }\n@@ -67,7 +67,7 @@ create_stash () {\n \tfi\n \n \t# state of the base commit\n-\tif b_commit=$(git rev-parse --verify HEAD)\n+\tif b_commit=$(git rev-parse --quiet --verify HEAD)\n \tthen\n \t\thead=$(git rev-list --oneline -n 1 HEAD --)\n \telse\n-- \n1.7.8.168.gd6118.dirty\n"},{"id":"181108","messageId":"7vsjkorlzp.fsf@alter.siamese.dyndns.org","threadId":"29158","inReplyTo":"20111214001432.GA2959@thinkpad","subject":"Re: [PATCH] stash: Fix multiple error messages on create if no HEAD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-14T01:16:26Z","receivedAt":"2011-12-14T01:16:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sebastian Morr <sebastian@morr.cc> writes:\n\n> This bugged me: In a new, empty repository:\n>\n>     $ git stash\n>     fatal: bad revision 'HEAD'\n>     fatal: bad revision 'HEAD'\n>     fatal: Needed a single revision\n>     You do not have the initial commit yet\n>\n> With this patch:\n>\n>     $ git stash\n>     You do not have the initial commit yet\n\nYeah, that looks tidier.\n\n> With the --quiet option, I wouldn't expect diff-index to print error\n> messages.\n\nEven with --quiet, an error is an error.\n\nAsking for a diff with the current HEAD when you do not have one yet _is_\nan error and \"diff-index\" is correct to report the error. The bug\n(i.e. \"git stash\" shows that error message) is in the program that calls\ndiff-index when the operation does not make sense.\n\n\"Hiding error\" is not desirable, especially if it is only for giving a\ncleaner error message for a narrow corner case that nobody cares\n(i.e. running \"stash\" when you do not have any commit to go back to), with\nthe side effect that it hides _real_ errors that may help users notice\nunusual situation (e.g. corrupted index file).\n\nProbably the right way to fix it is to check if HEAD is a valid commit\nbefore running any command that requires to have a valid HEAD (i.e.\ncreate and save would need one; list, show, etc. would not) and give that\n\"You do not have the initial commit yet\" message, before passing the\ncontrol to the implementations of these individual subcommands, without\ntouching the places you touched in this patch.\n\n>  no_changes () {\n> -\tgit diff-index --quiet --cached HEAD --ignore-submodules -- &&\n> +\tgit diff-index --quiet --cached HEAD --ignore-submodules -- 2>/dev/null &&\n>  \tgit diff-files --quiet --ignore-submodules &&\n>  \t(test -z \"$untracked\" || test -z \"$(untracked_files)\")\n>  }\n> @@ -67,7 +67,7 @@ create_stash () {\n>  \tfi\n>  \n>  \t# state of the base commit\n> -\tif b_commit=$(git rev-parse --verify HEAD)\n> +\tif b_commit=$(git rev-parse --quiet --verify HEAD)\n>  \tthen\n>  \t\thead=$(git rev-list --oneline -n 1 HEAD --)\n>  \telse\n"}]}