diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-09-03 19:18:03 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-09-03 19:18:04 -0700 |
commit | 5af77d13529a332bef99d22d0d983d5378edf534 (patch) | |
tree | 9e531fa4b19e0de9df5fe18c7fd95816360c7a19 | |
parent | 9d939886dbea58cf779f53f4c7b246a6562e184e (diff) | |
parent | ce113604672fed9b429b1c162b1005794fff6a17 (diff) | |
download | git-5af77d13529a332bef99d22d0d983d5378edf534.tar.gz |
Merge branch 'jk/log-missing-default-HEAD' into maint
"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
-rw-r--r-- | revision.c | 17 | ||||
-rwxr-xr-x | t/t4202-log.sh | 14 |
2 files changed, 30 insertions, 1 deletions
diff --git a/revision.c b/revision.c index ab97ffd459..9b9d77dc43 100644 --- a/revision.c +++ b/revision.c @@ -2173,6 +2173,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. @@ -2302,7 +2317,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); } diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 1b2e981a00..19277dd361 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -871,4 +871,18 @@ test_expect_success 'log --graph --no-walk is forbidden' ' test_must_fail git log --graph --no-walk ' +test_expect_success 'log diagnoses bogus HEAD' ' + git init empty && + test_must_fail git -C empty log 2>stderr && + test_i18ngrep does.not.have.any.commits stderr && + echo 1234abcd >empty/.git/refs/heads/master && + test_must_fail git -C empty log 2>stderr && + test_i18ngrep broken stderr && + echo "ref: refs/heads/invalid.lock" >empty/.git/HEAD && + test_must_fail git -C empty log 2>stderr && + test_i18ngrep broken stderr && + test_must_fail git -C empty log --default totally-bogus 2>stderr && + test_i18ngrep broken stderr +' + test_done |