diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-09-02 12:50:08 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-09-02 12:50:10 -0700 |
commit | 699a0f3748474fce7b688212c3f9ab25d7b750f5 (patch) | |
tree | 9b913deb5ef0e5855400f5c7e43f9d8f721aa90c /revision.c | |
parent | 7aa67f62c7cc0f5771dffe58c3234b6940d35a5d (diff) | |
parent | ce113604672fed9b429b1c162b1005794fff6a17 (diff) | |
download | git-699a0f3748474fce7b688212c3f9ab25d7b750f5.tar.gz |
Merge branch 'jk/log-missing-default-HEAD'
"git init empty && git -C empty log" said "bad default revision 'HEAD'",
which was found to be a bit confusing to new users.
* jk/log-missing-default-HEAD:
log: diagnose empty HEAD more clearly
Diffstat (limited to 'revision.c')
-rw-r--r-- | revision.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/revision.c b/revision.c index 5350139599..af2a18ed74 100644 --- a/revision.c +++ b/revision.c @@ -2187,6 +2187,21 @@ static int handle_revision_pseudo_opt(const char *submodule, return 1; } +static void NORETURN diagnose_missing_default(const char *def) +{ + unsigned char sha1[20]; + int flags; + const char *refname; + + refname = resolve_ref_unsafe(def, 0, sha1, &flags); + if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN)) + die(_("your current branch appears to be broken")); + + skip_prefix(refname, "refs/heads/", &refname); + die(_("your current branch '%s' does not have any commits yet"), + refname); +} + /* * Parse revision information, filling in the "rev_info" structure, * and removing the used arguments from the argument list. @@ -2316,7 +2331,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s struct object *object; struct object_context oc; if (get_sha1_with_context(revs->def, 0, sha1, &oc)) - die("bad default revision '%s'", revs->def); + diagnose_missing_default(revs->def); object = get_reference(revs, revs->def, sha1, 0); add_pending_object_with_mode(revs, object, revs->def, oc.mode); } |