git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leila Muhtasib <muhtasib@gmail.com>
To: git@vger.kernel.org
Cc: Leila Muhtasib <muhtasib@gmail.com>
Subject: [PATCH/RFC] revision: Show friendlier message.
Date: Sat, 23 Jun 2012 15:11:21 -0400	[thread overview]
Message-ID: <1340478681-58476-1-git-send-email-muhtasib@gmail.com> (raw)

'git log' on a newly initialized repository
(before any commits) shows an ugly message.

Signed-off-by: Leila Muhtasib <muhtasib@gmail.com>
---
I found this bug on the debian git bug list.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=412890

See scenario below:

% mkdir test
% cd test
% git init
Initialized empty Git repository in .git/
% git log
fatal: bad default revision 'HEAD'

I've reworded the error message to something friendlier.
I can change the message or add something like the link
suggests about 'Create or switch to an existent branch."
But I don't feel like that message quite captures the
scenario of initializing a new repository. Alternatively,
we can print the message using printf and exit successfully
instead of using 'die'.

Thanks,
Leila

 revision.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/revision.c b/revision.c
index 935e7a7..96add37 100644
--- a/revision.c
+++ b/revision.c
@@ -1821,8 +1821,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		unsigned char sha1[20];
 		struct object *object;
 		unsigned mode;
-		if (get_sha1_with_mode(revs->def, sha1, &mode))
-			die("bad default revision '%s'", revs->def);
+		if (get_sha1_with_mode(revs->def, sha1, &mode)) {
+			if (!strcmp(argv[0], "log") && !strcmp(revs->def, "HEAD"))
+				die("No commits to display.");
+			else
+				die("bad default revision '%s'", revs->def);
+		}
 		object = get_reference(revs, revs->def, sha1, 0);
 		add_pending_object_with_mode(revs, object, revs->def, mode);
 	}
-- 
1.7.7.5 (Apple Git-26)

             reply	other threads:[~2012-06-23 19:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-23 19:11 Leila Muhtasib [this message]
2012-06-25  5:28 ` [PATCH/RFC] revision: Show friendlier message Junio C Hamano
2012-06-25  5:58   ` Junio C Hamano
2012-06-25 19:14   ` Leila
2012-06-25 19:49     ` Junio C Hamano
2012-06-25 22:53       ` Leila
2012-06-25 23:07         ` Junio C Hamano
2012-06-26  3:46           ` Leila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340478681-58476-1-git-send-email-muhtasib@gmail.com \
    --to=muhtasib@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).