summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 171edcb)
raw | patch | inline | side by side (parent: 171edcb)
author | Michael J Gruber <git@drmicha.warpmail.net> | |
Sun, 28 Aug 2011 14:54:31 +0000 (16:54 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 29 Aug 2011 05:56:05 +0000 (22:56 -0700) |
Currently, there is no way to invoke the list mode explicitly, without
giving -v to force verbose output.
Introduce a --list option which invokes the list mode. This will be
beneficial for invoking list mode with pattern matching, which otherwise
would be interpreted as branch creation.
Along with --list, test also combinations of existing options.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
giving -v to force verbose output.
Introduce a --list option which invokes the list mode. This will be
beneficial for invoking list mode with pattern matching, which otherwise
would be interpreted as branch creation.
Along with --list, test also combinations of existing options.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-branch.txt | patch | blob | history | |
builtin/branch.c | patch | blob | history | |
t/t3200-branch.sh | patch | blob | history | |
t/t3203-branch-output.sh | patch | blob | history |
index 4c64ac939bfa5e4c527892a8224a8d308d7a8792..ac278fb154c6149464ca88d87e1b1e4de9c8b024 100644 (file)
--------
[verse]
'git branch' [--color[=<when>] | --no-color] [-r | -a]
- [-v [--abbrev=<length> | --no-abbrev]]
+ [--list] [-v [--abbrev=<length> | --no-abbrev]]
[(--merged | --no-merged | --contains) [<commit>]]
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
'git branch' (-m | -M) [<oldbranch>] <newbranch>
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.
+branches to be listed, and option `-a` shows both. This list mode is also
+activated by the `--list` and `-v` options (see below).
With `--contains`, shows only the branches that contain the named commit
(in other words, the branches whose tip commits are descendants of the
--all::
List both remote-tracking branches and local branches.
+--list::
+ Activate the list mode.
+
-v::
--verbose::
Show sha1 and commit subject line for each head, along with
relationship to upstream branch (if any). If given twice, print
the name of the upstream branch, as well.
+ `--list` is implied by all verbosity options.
--abbrev=<length>::
Alter the sha1's minimum display length in the output listing.
diff --git a/builtin/branch.c b/builtin/branch.c
index bd3a315b593044136b04e652e1736aaadefb47ea..a10929da8ed4a62f219882925d9d9bf1f23fc724 100644 (file)
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -612,7 +612,7 @@ static int opt_parse_merge_filter(const struct option *opt, const char *arg, int
int cmd_branch(int argc, const char **argv, const char *prefix)
{
- int delete = 0, rename = 0, force_create = 0;
+ int delete = 0, rename = 0, force_create = 0, list = 0;
int verbose = 0, abbrev = -1, detached = 0;
int reflog = 0;
enum branch_track track;
OPT_BIT('D', NULL, &delete, "delete branch (even if not merged)", 2),
OPT_BIT('m', "move", &rename, "move/rename a branch and its reflog", 1),
OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
+ OPT_BOOLEAN(0, "list", &list, "list branch names"),
OPT_BOOLEAN('l', "create-reflog", &reflog, "create the branch's reflog"),
OPT__FORCE(&force_create, "force creation (when already exists)"),
{
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
0);
- if (!!delete + !!rename + !!force_create > 1)
+
+ if (!delete && !rename && !force_create &&
+ (argc == 0 || (verbose && argc)))
+ list = 1;
+
+ if (!!delete + !!rename + !!force_create + !!list > 1)
usage_with_options(builtin_branch_usage, options);
if (abbrev == -1)
if (delete)
return delete_branches(argc, argv, delete > 1, kinds);
- else if (argc == 0)
+ else if (list)
return print_ref_list(kinds, detached, verbose, abbrev, with_commit);
else if (rename && (argc == 1))
rename_branch(head, argv[0], rename > 1);
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 9e69c8c926620f06343e64e7b3aa3e4ada5a6b69..c466b2065dd76a505a6e2ef946cd8c9866090780 100755 (executable)
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
test_must_fail git branch -m q r/q
'
+test_expect_success 'git branch -v -d t should work' '
+ git branch t &&
+ test .git/refs/heads/t &&
+ git branch -v -d t &&
+ test ! -f .git/refs/heads/t
+'
+
+test_expect_success 'git branch -v -m t s should work' '
+ git branch t &&
+ test .git/refs/heads/t &&
+ git branch -v -m t s &&
+ test ! -f .git/refs/heads/t &&
+ test -f .git/refs/heads/s &&
+ git branch -d s
+'
+
+test_expect_success 'git branch -m -d t s should fail' '
+ git branch t &&
+ test .git/refs/heads/t &&
+ test_must_fail git branch -m -d t s &&
+ git branch -d t &&
+ test ! -f .git/refs/heads/t
+'
+
+test_expect_success 'git branch --list -d t should fail' '
+ git branch t &&
+ test .git/refs/heads/t &&
+ test_must_fail git branch --list -d t &&
+ git branch -d t &&
+ test ! -f .git/refs/heads/t
+'
+
mv .git/config .git/config-saved
test_expect_success 'git branch -m q q2 without config should succeed' '
index 6b7c118e4fcbf3855318b2e9e3b721d07950fd25..97d10b1884d39cdef6efc9a0ce7384d7538ea366 100755 (executable)
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
test_cmp expect actual
'
+test_expect_success 'git branch --list shows local branches' '
+ git branch --list >actual &&
+ test_cmp expect actual
+'
+
cat >expect <<'EOF'
origin/HEAD -> origin/branch-one
origin/branch-one