Code

Merge branch 'jn/maint-fast-import-empty-ls' into maint
[git.git] / builtin / branch.c
index 7095718c13b5c4f39186548f5ed12198a3b9e609..d8cccf725d3fab24ad585a26629373fc987bb3f8 100644 (file)
@@ -530,6 +530,10 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
        if (merge_filter != NO_FILTER) {
                struct commit *filter;
                filter = lookup_commit_reference_gently(merge_filter_ref, 0);
+               if (!filter)
+                       die("object '%s' does not point to a commit",
+                           sha1_to_hex(merge_filter_ref));
+
                filter->object.flags |= UNINTERESTING;
                add_pending_object(&ref_list.revs,
                                   (struct object *) filter, "");
@@ -768,6 +772,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                                      with_commit, argv);
        else if (edit_description) {
                const char *branch_name;
+               struct strbuf branch_ref = STRBUF_INIT;
+
                if (detached)
                        die("Cannot give description to detached HEAD");
                if (!argc)
@@ -776,6 +782,19 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        branch_name = argv[0];
                else
                        usage_with_options(builtin_branch_usage, options);
+
+               strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
+               if (!ref_exists(branch_ref.buf)) {
+                       strbuf_release(&branch_ref);
+
+                       if (!argc)
+                               return error("No commit on branch '%s' yet.",
+                                            branch_name);
+                       else
+                               return error("No such branch '%s'.", branch_name);
+               }
+               strbuf_release(&branch_ref);
+
                if (edit_branch_description(branch_name))
                        return 1;
        } else if (rename) {