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

[PATCH/RFC] revision: Show friendlier message.

From
Leila Muhtasib <muhtasib@gmail.com>
Date
Jun 23, 2012, 19:11 UTC
Message-ID
<1340478681-58476-1-git-send-email-muhtasib@gmail.com>

'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)
Next: Junio C Hamano
Message 1 of 8 in “revision: Show friendlier message.”
  1. revision: Show friendlier message.Leila Muhtasib, Jun 23, 2012
  2. Junio C HamanoJun 25, 2012
  3. Junio C HamanoJun 25, 2012
  4. LeilaJun 25, 2012
  5. Junio C HamanoJun 25, 2012
  6. LeilaJun 25, 2012
  7. Junio C HamanoJun 25, 2012
  8. LeilaJun 26, 2012

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.