documentation: trivial whitespace cleanups
[gitweb.git] / builtin / branch.c
index 947c84be2daac5fd183c2d1fbd706e239eab63c5..00d17d25d1866323f9e1dffcb334a573f5de5221 100644 (file)
@@ -466,7 +466,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
                             int verbose, int abbrev)
 {
        struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
-       const char *sub = " **** invalid ref ****";
+       const char *sub = _(" **** invalid ref ****");
        struct commit *commit = item->commit;
 
        if (commit && !parse_commit(commit)) {
@@ -590,7 +590,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
                struct commit *filter;
                filter = lookup_commit_reference_gently(merge_filter_ref, 0);
                if (!filter)
-                       die("object '%s' does not point to a commit",
+                       die(_("object '%s' does not point to a commit"),
                            sha1_to_hex(merge_filter_ref));
 
                filter->object.flags |= UNINTERESTING;
@@ -706,11 +706,11 @@ static int edit_branch_description(const char *branch_name)
        read_branch_desc(&buf, branch_name);
        if (!buf.len || buf.buf[buf.len-1] != '\n')
                strbuf_addch(&buf, '\n');
-       strbuf_addf(&buf,
-                   "Please edit the description for the branch\n"
-                   "  %s\n"
-                   "# Lines starting with '#' will be stripped.\n",
-                   branch_name);
+       strbuf_commented_addf(&buf,
+                   "Please edit the description for the branch\n"
+                   "  %s\n"
+                   "Lines starting with '%c' will be stripped.\n",
+                   branch_name, comment_line_char);
        fp = fopen(git_path(edit_description), "w");
        if ((fwrite(buf.buf, 1, buf.len, fp) < buf.len) || fclose(fp)) {
                strbuf_release(&buf);
@@ -725,7 +725,7 @@ static int edit_branch_description(const char *branch_name)
        stripspace(&buf, 1);
 
        strbuf_addf(&name, "branch.%s.description", branch_name);
-       status = git_config_set(name.buf, buf.buf);
+       status = git_config_set(name.buf, buf.len ? buf.buf : NULL);
        strbuf_release(&name);
        strbuf_release(&buf);
 
@@ -825,6 +825,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0)
                list = 1;
 
+       if (with_commit || merge_filter != NO_FILTER)
+               list = 1;
+
        if (!!delete + !!rename + !!force_create + !!list + !!new_upstream + !!unset_upstream > 1)
                usage_with_options(builtin_branch_usage, options);
 
@@ -837,9 +840,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                colopts = 0;
        }
 
-       if (delete)
+       if (delete) {
+               if (!argc)
+                       die(_("branch name required"));
                return delete_branches(argc, argv, delete > 1, kinds, quiet);
-       else if (list) {
+       else if (list) {
                int ret = print_ref_list(kinds, detached, verbose, abbrev,
                                         with_commit, argv);
                print_columns(&output, colopts, NULL);
@@ -852,22 +857,23 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
                if (!argc) {
                        if (detached)
-                               die("Cannot give description to detached HEAD");
+                               die(_("Cannot give description to detached HEAD"));
                        branch_name = head;
                } else if (argc == 1)
                        branch_name = argv[0];
                else
-                       usage_with_options(builtin_branch_usage, options);
+                       die(_("cannot edit description of more than one branch"));
 
                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.",
+                               return error(_("No commit on branch '%s' yet."),
                                             branch_name);
                        else
-                               return error("No such branch '%s'.", branch_name);
+                               return error(_("No branch named '%s'."),
+                                            branch_name);
                }
                strbuf_release(&branch_ref);
 
@@ -879,10 +885,21 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                else if (argc == 2)
                        rename_branch(argv[0], argv[1], rename > 1);
                else
-                       usage_with_options(builtin_branch_usage, options);
+                       die(_("too many branches for a rename operation"));
        } else if (new_upstream) {
                struct branch *branch = branch_get(argv[0]);
 
+               if (argc > 1)
+                       die(_("too many branches to set new upstream"));
+
+               if (!branch) {
+                       if (!argc || !strcmp(argv[0], "HEAD"))
+                               die(_("could not set upstream of HEAD to %s when "
+                                     "it does not point to any branch."),
+                                   new_upstream);
+                       die(_("no such branch '%s'"), argv[0]);
+               }
+
                if (!ref_exists(branch->refname))
                        die(_("branch '%s' does not exist"), branch->name);
 
@@ -895,6 +912,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                struct branch *branch = branch_get(argv[0]);
                struct strbuf buf = STRBUF_INIT;
 
+               if (argc > 1)
+                       die(_("too many branches to unset upstream"));
+
+               if (!branch) {
+                       if (!argc || !strcmp(argv[0], "HEAD"))
+                               die(_("could not unset upstream of HEAD when "
+                                     "it does not point to any branch."));
+                       die(_("no such branch '%s'"), argv[0]);
+               }
+
                if (!branch_has_merge_config(branch)) {
                        die(_("Branch '%s' has no upstream information"), branch->name);
                }
@@ -910,6 +937,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                int branch_existed = 0, remote_tracking = 0;
                struct strbuf buf = STRBUF_INIT;
 
+               if (!strcmp(argv[0], "HEAD"))
+                       die(_("it does not make sense to create 'HEAD' manually"));
+
+               if (!branch)
+                       die(_("no such branch '%s'"), argv[0]);
+
                if (kinds != REF_LOCAL_BRANCH)
                        die(_("-a and -r options to 'git branch' do not make sense with a branch name"));