From: Junio C Hamano Date: Thu, 7 Feb 2013 22:41:38 +0000 (-0800) Subject: Merge branch 'nd/branch-error-cases' X-Git-Tag: v1.8.2-rc0~44 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f507784d2c956fc73f3791b04cc80e7e0dae0a4d?ds=inline;hp=-c Merge branch 'nd/branch-error-cases' Fix various error messages and conditions in "git branch", e.g. we advertised "branch -d/-D" to remove one or more branches but actually implemented removal of zero or more branches---request to remove no branches was not rejected. * nd/branch-error-cases: branch: let branch filters imply --list docs: clarify git-branch --list behavior branch: mark more strings for translation branch: give a more helpful message on redundant arguments branch: reject -D/-d without branch name --- f507784d2c956fc73f3791b04cc80e7e0dae0a4d diff --combined Documentation/git-branch.txt index d4a9be22e6,597d64ec1f..b7cb625b89 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@@ -22,13 -22,15 +22,15 @@@ SYNOPSI DESCRIPTION ----------- - With no arguments, existing branches are listed and the current branch will - be highlighted with an asterisk. Option `-r` causes the remote-tracking - branches to be listed, and option `-a` shows both. This list mode is also - activated by the `--list` option (see below). - restricts the output to matching branches, the pattern is a shell - wildcard (i.e., matched using fnmatch(3)). - Multiple patterns may be given; if any of them matches, the branch is shown. + If `--list` is given, or if there are no non-option arguments, existing + branches are listed; the current branch will be highlighted with an + asterisk. Option `-r` causes the remote-tracking branches to be listed, + and option `-a` shows both local and remote branches. If a `` + is given, it is used as a shell wildcard to restrict the output to + matching branches. If multiple patterns are given, a branch is shown if + it matches any of the patterns. Note that when providing a + ``, you must use `--list`; otherwise the command is interpreted + as branch creation. With `--contains`, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the @@@ -45,7 -47,7 +47,7 @@@ Note that this will create the new bran working tree to it; use "git checkout " to switch to the new branch. -When a local branch is started off a remote-tracking branch, git sets up the +When a local branch is started off a remote-tracking branch, Git sets up the branch so that 'git pull' will appropriately merge from the remote-tracking branch. This behavior may be changed via the global `branch.autosetupmerge` configuration flag. That setting can be @@@ -193,15 -195,15 +195,15 @@@ start-point is either a local or remote --contains []:: Only list branches which contain the specified commit (HEAD - if not specified). + if not specified). Implies `--list`. --merged []:: Only list branches whose tips are reachable from the - specified commit (HEAD if not specified). + specified commit (HEAD if not specified). Implies `--list`. --no-merged []:: Only list branches whose tips are not reachable from the - specified commit (HEAD if not specified). + specified commit (HEAD if not specified). Implies `--list`. :: The name of the branch to create or delete. diff --combined builtin/branch.c index 77b435825c,bd2c36b706..6371bf96c4 --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -466,7 -466,7 +466,7 @@@ static void add_verbose_info(struct str 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 +590,7 @@@ static int print_ref_list(int kinds, in 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 +706,11 @@@ static int edit_branch_description(cons 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); @@@ -825,6 -825,9 +825,9 @@@ int cmd_branch(int argc, const char **a 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 +840,11 @@@ 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 +857,23 @@@ 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,7 -885,7 +885,7 @@@ 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]);