From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCHv4 4/5] branch: introduce --list option
Date: Thu, 8 Sep 2011 16:25:57 +0200 [thread overview]
Message-ID: <c259dcbada3de282325b59b143209ace57ff8b9d.1315491900.git.git@drmicha.warpmail.net> (raw)
In-Reply-To: <4E6889DF.7030404@drmicha.warpmail.net>
In-Reply-To: <cover.1315491900.git.git@drmicha.warpmail.net>
Currently, there is no way to invoke the list mode explicitly.
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>
---
Documentation/git-branch.txt | 11 ++++++++---
builtin/branch.c | 11 ++++++++---
t/t3200-branch.sh | 32 ++++++++++++++++++++++++++++++++
t/t3203-branch-output.sh | 5 +++++
4 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 4c64ac9..26024b6 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -9,7 +9,7 @@ SYNOPSIS
--------
[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>
@@ -20,7 +20,8 @@ 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.
+branches to be listed, and option `-a` shows both. This list mode is also
+activated by the `--list` option (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
@@ -110,9 +111,13 @@ OPTIONS
--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
+ When in list mode,
+ 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.
diff --git a/builtin/branch.c b/builtin/branch.c
index bd3a315..b17ad26 100644
--- 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;
@@ -651,6 +651,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
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)"),
{
@@ -693,7 +694,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
0);
- if (!!delete + !!rename + !!force_create > 1)
+
+ if (!delete && !rename && !force_create && argc == 0)
+ list = 1;
+
+ if (!!delete + !!rename + !!force_create + !!list > 1)
usage_with_options(builtin_branch_usage, options);
if (abbrev == -1)
@@ -701,7 +706,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
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 9e69c8c..c466b20 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -98,6 +98,38 @@ test_expect_success 'git branch -m q r/q should fail when r exists' '
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' '
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 6b7c118..97d10b1 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -32,6 +32,11 @@ test_expect_success 'git branch shows local branches' '
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
--
1.7.7.rc0.469.g9eb94
next prev parent reply other threads:[~2011-09-08 14:26 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 17:17 [RFC] branch: list branches by single remote Michael Schubert
2011-08-04 4:06 ` Jeff King
2011-08-16 13:37 ` Michael J Gruber
2011-08-16 14:19 ` Michael Schubert
2011-08-16 15:14 ` Jeff King
2011-08-24 15:14 ` Michael Schubert
2011-08-24 15:37 ` Michael J Gruber
2011-08-24 16:02 ` Michael Schubert
2011-08-24 18:34 ` Junio C Hamano
2011-08-25 2:31 ` Thiago Farina
2011-08-25 18:02 ` Junio C Hamano
2011-08-25 8:29 ` Michael J Gruber
2011-08-25 8:30 ` [PATCH 0/5] RFC: patterns for branch list Michael J Gruber
2011-08-25 8:30 ` [PATCH 1/5] branch: allow pattern arguments Michael J Gruber
2011-08-25 17:54 ` Jeff King
2011-08-25 18:32 ` Junio C Hamano
2011-08-25 19:29 ` Junio C Hamano
2011-08-25 8:30 ` [PATCH 2/5] branch: introduce --list argument Michael J Gruber
2011-08-25 18:34 ` Junio C Hamano
2011-08-25 19:52 ` Junio C Hamano
2011-08-25 8:30 ` [PATCH 3/5] t6040; test branch -vv Michael J Gruber
2011-08-25 8:30 ` [PATCH 4/5] branch: restructure -v vs. -vv Michael J Gruber
2011-08-25 19:02 ` Junio C Hamano
2011-08-25 8:30 ` [PATCH 5/5] branch: give patchsame count with -vvv Michael J Gruber
2011-08-25 17:53 ` [PATCH 0/5] RFC: patterns for branch list Jeff King
2011-08-26 8:30 ` Michael J Gruber
2011-08-26 16:55 ` Junio C Hamano
2011-09-07 19:53 ` Jeff King
2011-09-08 9:20 ` Michael J Gruber
2011-08-26 14:05 ` [PATCHv2 0/5] " Michael J Gruber
2011-08-26 14:05 ` [PATCHv2 1/5] t6040: test branch -vv Michael J Gruber
2011-08-26 14:05 ` [PATCHv2 2/5] git-tag: introduce long forms for the options Michael J Gruber
2011-08-26 17:11 ` Junio C Hamano
2011-08-28 14:03 ` Michael J Gruber
2011-08-26 14:05 ` [PATCHv2 3/5] git-branch: introduce missing " Michael J Gruber
2011-08-26 17:13 ` Junio C Hamano
2011-08-28 14:05 ` Michael J Gruber
2011-08-26 14:05 ` [PATCHv2 4/5] branch: introduce --list option Michael J Gruber
2011-08-26 17:43 ` Junio C Hamano
2011-08-28 14:37 ` Michael J Gruber
2011-09-07 19:56 ` Jeff King
2011-09-08 9:24 ` Michael J Gruber
2011-09-08 14:25 ` [PATCHv4 0/5] mg/branch-list amendment Michael J Gruber
2011-09-08 14:25 ` Michael J Gruber [this message]
2011-09-08 14:25 ` [PATCHv4 5/5] branch: allow pattern arguments Michael J Gruber
2011-09-08 21:03 ` [PATCHv2 4/5] branch: introduce --list option Junio C Hamano
2011-09-08 21:11 ` Jeff King
2011-09-08 21:17 ` Junio C Hamano
2011-09-09 1:08 ` Jeff King
2011-09-09 6:54 ` Michael J Gruber
2011-09-09 16:02 ` Junio C Hamano
2011-09-09 19:29 ` Michael J Gruber
2011-09-09 19:30 ` Jeff King
2011-09-09 19:40 ` [PATCH] t3200: test branch creation with -v Michael J Gruber
2011-09-09 19:43 ` Jeff King
2011-09-09 19:45 ` Jeff King
2011-09-10 13:29 ` Michael J Gruber
2011-09-13 3:57 ` Jeff King
2011-09-13 12:12 ` Michael J Gruber
2011-09-13 16:13 ` [PATCH] t3200: clean up checks for file existence Jeff King
2011-09-13 17:13 ` Junio C Hamano
2011-09-13 17:16 ` Jeff King
2011-08-26 14:05 ` [PATCHv2 5/5] branch: allow pattern arguments Michael J Gruber
2011-08-26 18:45 ` Junio C Hamano
2011-08-28 14:54 ` [PATCHv3 0/5] patterns for branch list Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 1/5] t6040: test branch -vv Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 2/5] git-tag: introduce long forms for the options Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 3/5] git-branch: introduce missing " Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 4/5] branch: introduce --list option Michael J Gruber
2011-08-29 5:55 ` Junio C Hamano
2011-08-29 6:35 ` Michael J Gruber
2011-08-29 6:51 ` Junio C Hamano
2011-08-28 14:54 ` [PATCHv3 5/5] branch: allow pattern arguments Michael J Gruber
2011-09-06 13:10 ` Michael Schubert
2011-09-06 14:21 ` Michael J Gruber
2011-09-06 14:26 ` Sverre Rabbelier
2011-09-06 16:11 ` Michael J Gruber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c259dcbada3de282325b59b143209ace57ff8b9d.1315491900.git.git@drmicha.warpmail.net \
--to=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).