* [PATCHv2 1/5] t6040: test branch -vv
2011-08-26 14:05 ` [PATCHv2 0/5] " Michael J Gruber
@ 2011-08-26 14:05 ` Michael J Gruber
2011-08-26 14:05 ` [PATCHv2 2/5] git-tag: introduce long forms for the options Michael J Gruber
` (4 subsequent siblings)
5 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-26 14:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
t6040 has a test for 'git branch -v' but not for 'git branch -vv'.
Add one.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
t/t6040-tracking-info.sh | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 19de5b1..19272bc 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -51,6 +51,22 @@ test_expect_success 'branch -v' '
test_i18ncmp expect actual
'
+cat >expect <<\EOF
+b1 origin/master: ahead 1, behind 1
+b2 origin/master: ahead 1, behind 1
+b3 origin/master: behind 1
+b4 origin/master: ahead 2
+EOF
+
+test_expect_success 'branch -vv' '
+ (
+ cd test &&
+ git branch -vv
+ ) |
+ sed -n -e "$script" >actual &&
+ test_i18ncmp expect actual
+'
+
test_expect_success 'checkout' '
(
cd test && git checkout b1
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [PATCHv2 2/5] git-tag: introduce long forms for the options
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 ` Michael J Gruber
2011-08-26 17:11 ` Junio C Hamano
2011-08-26 14:05 ` [PATCHv2 3/5] git-branch: introduce missing " Michael J Gruber
` (3 subsequent siblings)
5 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-26 14:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Long forms are better to memoize, and more reliably uniform across
commands.
Design notes:
-u,--local-user is named following the analogous gnupg option.
-l,--list is not an argument taking option but a mode switch.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Documentation/git-tag.txt | 8 ++++++++
builtin/tag.c | 16 ++++++++--------
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index fb1c0ac..c83cb13 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -43,12 +43,15 @@ GnuPG key for signing.
OPTIONS
-------
-a::
+--annotate::
Make an unsigned, annotated tag object
-s::
+--sign::
Make a GPG-signed tag, using the default e-mail address's key
-u <key-id>::
+--local-user=<key-id>::
Make a GPG-signed tag, using the given key
-f::
@@ -56,9 +59,11 @@ OPTIONS
Replace an existing tag with the given name (instead of failing)
-d::
+--delete::
Delete existing tags with the given names.
-v::
+--verify::
Verify the gpg signature of the given tag names.
-n<num>::
@@ -69,6 +74,7 @@ OPTIONS
If the tag is not annotated, the commit message is displayed instead.
-l <pattern>::
+--list <pattern>::
List tags with names that match the given pattern (or all if no
pattern is given). Running "git tag" without arguments also
lists all tags. The pattern is a shell wildcard (i.e., matched
@@ -79,6 +85,7 @@ OPTIONS
Only list tags which contain the specified commit.
-m <msg>::
+--message=<msg>::
Use the given tag message (instead of prompting).
If multiple `-m` options are given, their values are
concatenated as separate paragraphs.
@@ -86,6 +93,7 @@ OPTIONS
is given.
-F <file>::
+--file=<file>::
Take the tag message from the given file. Use '-' to
read the message from the standard input.
Implies `-a` if none of `-a`, `-s`, or `-u <key-id>`
diff --git a/builtin/tag.c b/builtin/tag.c
index 667515e..9d89616 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -429,21 +429,21 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct msg_arg msg = { 0, STRBUF_INIT };
struct commit_list *with_commit = NULL;
struct option options[] = {
- OPT_BOOLEAN('l', NULL, &list, "list tag names"),
+ OPT_BOOLEAN('l', "list", &list, "list tag names"),
{ OPTION_INTEGER, 'n', NULL, &lines, "n",
"print <n> lines of each tag message",
PARSE_OPT_OPTARG, NULL, 1 },
- OPT_BOOLEAN('d', NULL, &delete, "delete tags"),
- OPT_BOOLEAN('v', NULL, &verify, "verify tags"),
+ OPT_BOOLEAN('d', "delete", &delete, "delete tags"),
+ OPT_BOOLEAN('v', "verify", &verify, "verify tags"),
OPT_GROUP("Tag creation options"),
- OPT_BOOLEAN('a', NULL, &annotate,
+ OPT_BOOLEAN('a', "annotate", &annotate,
"annotated tag, needs a message"),
- OPT_CALLBACK('m', NULL, &msg, "message",
+ OPT_CALLBACK('m', "message", &msg, "message",
"tag message", parse_msg_arg),
- OPT_FILENAME('F', NULL, &msgfile, "read message from file"),
- OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
- OPT_STRING('u', NULL, &keyid, "key-id",
+ OPT_FILENAME('F', "file", &msgfile, "read message from file"),
+ OPT_BOOLEAN('s', "sign", &sign, "annotated and GPG-signed tag"),
+ OPT_STRING('u', "local-user", &keyid, "key-id",
"use another key to sign the tag"),
OPT__FORCE(&force, "replace the tag if exists"),
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv2 2/5] git-tag: introduce long forms for the options
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
0 siblings, 1 reply; 77+ messages in thread
From: Junio C Hamano @ 2011-08-26 17:11 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano, Jeff King
Michael J Gruber <git@drmicha.warpmail.net> writes:
> Long forms are better to memoize, and more reliably uniform across
> commands.
I think people "memorize" and machines "memoize"; machines will do so just
fine without long forms, but I think you are talking about helping people.
The part after ", and" lacks a verb, making it a non-sentence.
> Design notes:
>
> -u,--local-user is named following the analogous gnupg option.
>
> -l,--list is not an argument taking option but a mode switch.
Ok.
The remainder looks good. Thanks.
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 2/5] git-tag: introduce long forms for the options
2011-08-26 17:11 ` Junio C Hamano
@ 2011-08-28 14:03 ` Michael J Gruber
0 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:03 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King
Junio C Hamano venit, vidit, dixit 26.08.2011 19:11:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> Long forms are better to memoize, and more reliably uniform across
>> commands.
>
> I think people "memorize" and machines "memoize"; machines will do so just
> fine without long forms, but I think you are talking about helping people.
Yep.
> The part after ", and" lacks a verb, making it a non-sentence.
They are better to memorize, and they are more reliably uniform... Maybe
drop the comma?
>
>> Design notes:
>>
>> -u,--local-user is named following the analogous gnupg option.
>>
>> -l,--list is not an argument taking option but a mode switch.
>
> Ok.
>
> The remainder looks good. Thanks.
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv2 3/5] git-branch: introduce missing long forms for the options
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 14:05 ` Michael J Gruber
2011-08-26 17:13 ` Junio C Hamano
2011-08-26 14:05 ` [PATCHv2 4/5] branch: introduce --list option Michael J Gruber
` (2 subsequent siblings)
5 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-26 14:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Long forms are better to memoize, and more reliably uniform across
commands.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
I'm somewhat torn between --move and --rename for -m. We have no real precedent
besides "git remote rename".
I left out -M and -D because I feel they should really be -m -f resp. -d -f.
---
Documentation/git-branch.txt | 5 +++++
builtin/branch.c | 10 +++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 507b8d0..4c64ac9 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -64,6 +64,7 @@ way to clean up all obsolete remote-tracking branches.
OPTIONS
-------
-d::
+--delete::
Delete a branch. The branch must be fully merged in its
upstream branch, or in `HEAD` if no upstream was set with
`--track` or `--set-upstream`.
@@ -72,6 +73,7 @@ OPTIONS
Delete a branch irrespective of its merged status.
-l::
+--create-reflog::
Create the branch's reflog. This activates recording of
all changes made to the branch ref, enabling use of date
based sha1 expressions such as "<branchname>@\{yesterday}".
@@ -84,6 +86,7 @@ OPTIONS
already. Without `-f` 'git branch' refuses to change an existing branch.
-m::
+--move::
Move/rename a branch and the corresponding reflog.
-M::
@@ -100,9 +103,11 @@ OPTIONS
Same as `--color=never`.
-r::
+--remotes::
List or delete (if used with -d) the remote-tracking branches.
-a::
+--all::
List both remote-tracking branches and local branches.
-v::
diff --git a/builtin/branch.c b/builtin/branch.c
index aa705a0..94e41ae 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -624,7 +624,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_SET_INT( 0, "set-upstream", &track, "change upstream info",
BRANCH_TRACK_OVERRIDE),
OPT__COLOR(&branch_use_color, "use colored output"),
- OPT_SET_INT('r', NULL, &kinds, "act on remote-tracking branches",
+ OPT_SET_INT('r', "remotes", &kinds, "act on remote-tracking branches",
REF_REMOTE_BRANCH),
{
OPTION_CALLBACK, 0, "contains", &with_commit, "commit",
@@ -641,13 +641,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT__ABBREV(&abbrev),
OPT_GROUP("Specific git-branch actions:"),
- OPT_SET_INT('a', NULL, &kinds, "list both remote-tracking and local branches",
+ OPT_SET_INT('a', "all", &kinds, "list both remote-tracking and local branches",
REF_REMOTE_BRANCH | REF_LOCAL_BRANCH),
- OPT_BIT('d', NULL, &delete, "delete fully merged branch", 1),
+ OPT_BIT('d', "delete", &delete, "delete fully merged branch", 1),
OPT_BIT('D', NULL, &delete, "delete branch (even if not merged)", 2),
- OPT_BIT('m', NULL, &rename, "move/rename a branch and its reflog", 1),
+ 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('l', NULL, &reflog, "create the branch's reflog"),
+ OPT_BOOLEAN('l', "create-reflog", &reflog, "create the branch's reflog"),
OPT__FORCE(&force_create, "force creation (when already exists)"),
{
OPTION_CALLBACK, 0, "no-merged", &merge_filter_ref,
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv2 3/5] git-branch: introduce missing long forms for the options
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
0 siblings, 1 reply; 77+ messages in thread
From: Junio C Hamano @ 2011-08-26 17:13 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Jeff King
Michael J Gruber <git@drmicha.warpmail.net> writes:
> @@ -100,9 +103,11 @@ OPTIONS
> Same as `--color=never`.
>
> -r::
> +--remotes::
> List or delete (if used with -d) the remote-tracking branches.
I am not sure if this should be "--remoteS".
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 3/5] git-branch: introduce missing long forms for the options
2011-08-26 17:13 ` Junio C Hamano
@ 2011-08-28 14:05 ` Michael J Gruber
0 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King
Junio C Hamano venit, vidit, dixit 26.08.2011 19:13:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> @@ -100,9 +103,11 @@ OPTIONS
>> Same as `--color=never`.
>>
>> -r::
>> +--remotes::
>> List or delete (if used with -d) the remote-tracking branches.
>
> I am not sure if this should be "--remoteS".
like "git log --remotes".
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv2 4/5] branch: introduce --list option
2011-08-26 14:05 ` [PATCHv2 0/5] " Michael J Gruber
` (2 preceding siblings ...)
2011-08-26 14:05 ` [PATCHv2 3/5] git-branch: introduce missing " Michael J Gruber
@ 2011-08-26 14:05 ` Michael J Gruber
2011-08-26 17:43 ` Junio C Hamano
2011-08-26 14:05 ` [PATCHv2 5/5] branch: allow pattern arguments Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 0/5] patterns for branch list Michael J Gruber
5 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-26 14:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
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.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Documentation/git-branch.txt | 9 +++++++--
builtin/branch.c | 12 +++++++++---
t/t3203-branch-output.sh | 14 ++++++++++++++
3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 4c64ac9..ac278fb 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` 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
@@ -110,11 +111,15 @@ 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
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 94e41ae..4a33b07 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -608,7 +608,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;
@@ -647,6 +647,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)"),
{
@@ -686,7 +687,12 @@ 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 || (verbose && argc)))
+ list = 1;
+
+ if (!!delete + !!rename + !!force_create + !!list > 1)
usage_with_options(builtin_branch_usage, options);
if (abbrev == -1)
@@ -694,7 +700,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/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 6b7c118..61e095c 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -32,6 +32,20 @@ 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'
+ branch-one
+ branch-two
+EOF
+test_expect_success 'git branch --list pattern shows matching local branches' '
+ git branch --list branch* >actual &&
+ test_cmp expect actual
+'
+
cat >expect <<'EOF'
origin/HEAD -> origin/branch-one
origin/branch-one
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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
0 siblings, 1 reply; 77+ messages in thread
From: Junio C Hamano @ 2011-08-26 17:43 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Jeff King
Michael J Gruber <git@drmicha.warpmail.net> writes:
> 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.
>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---
> @@ -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` and `-v` options (see below).
Very good to mention "and -v" here ;-)
> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
> index 6b7c118..61e095c 100755
> --- a/t/t3203-branch-output.sh
> +++ b/t/t3203-branch-output.sh
> @@ -32,6 +32,20 @@ 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'
> + branch-one
> + branch-two
> +EOF
> +test_expect_success 'git branch --list pattern shows matching local branches' '
> + git branch --list branch* >actual &&
> + test_cmp expect actual
> +'
> +
Could we have a test to check the code you updated to sanity check the
combination of options as well? I suspect the reason your initial round
botched the "branch -v -m foo" without realizing may be because we do not
cover the error checking.
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
2011-08-26 17:43 ` Junio C Hamano
@ 2011-08-28 14:37 ` Michael J Gruber
2011-09-07 19:56 ` Jeff King
0 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:37 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King
Junio C Hamano venit, vidit, dixit 26.08.2011 19:43:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> 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.
>>
>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
>> ---
>
>> @@ -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` and `-v` options (see below).
>
> Very good to mention "and -v" here ;-)
>
>> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
>> index 6b7c118..61e095c 100755
>> --- a/t/t3203-branch-output.sh
>> +++ b/t/t3203-branch-output.sh
>> @@ -32,6 +32,20 @@ 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'
>> + branch-one
>> + branch-two
>> +EOF
>> +test_expect_success 'git branch --list pattern shows matching local branches' '
>> + git branch --list branch* >actual &&
>> + test_cmp expect actual
>> +'
>> +
>
> Could we have a test to check the code you updated to sanity check the
> combination of options as well? I suspect the reason your initial round
> botched the "branch -v -m foo" without realizing may be because we do not
> cover the error checking.
Currently, "-m -d" is forbidden", but "-m -v" is "-m", same for "-d -v".
Do we want to keep it like that? Probably. I'll add the tests to 4/5.
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
2011-08-28 14:37 ` Michael J Gruber
@ 2011-09-07 19:56 ` Jeff King
2011-09-08 9:24 ` Michael J Gruber
0 siblings, 1 reply; 77+ messages in thread
From: Jeff King @ 2011-09-07 19:56 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Junio C Hamano, git
On Sun, Aug 28, 2011 at 04:37:04PM +0200, Michael J Gruber wrote:
> Currently, "-m -d" is forbidden", but "-m -v" is "-m", same for "-d -v".
> Do we want to keep it like that? Probably. I'll add the tests to 4/5.
Yes, I think so. "-v" just means "be more verbose"; the fact that
there is currently nothing to be more verbose about with "-m" and "-d"
is irrelevant.
It does make me a little nervous about the "'git branch -v'
automatically means 'git branch --list -v'" patch, though. It closes the
door in the future to us being more or less verbose about branch
creation details (and while helpful, it creates a slight inconsistency
in the interface).
If we are adding "-l" anyway, is it really necessary? It's not much
harder to do "git branch -lv" once that is in place.
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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 21:03 ` [PATCHv2 4/5] branch: introduce --list option Junio C Hamano
0 siblings, 2 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-09-08 9:24 UTC (permalink / raw)
To: Jeff King; +Cc: Junio C Hamano, git
Jeff King venit, vidit, dixit 07.09.2011 21:56:
> On Sun, Aug 28, 2011 at 04:37:04PM +0200, Michael J Gruber wrote:
>
>> Currently, "-m -d" is forbidden", but "-m -v" is "-m", same for "-d -v".
>> Do we want to keep it like that? Probably. I'll add the tests to 4/5.
>
> Yes, I think so. "-v" just means "be more verbose"; the fact that
> there is currently nothing to be more verbose about with "-m" and "-d"
> is irrelevant.
>
> It does make me a little nervous about the "'git branch -v'
> automatically means 'git branch --list -v'" patch, though. It closes the
> door in the future to us being more or less verbose about branch
> creation details (and while helpful, it creates a slight inconsistency
> in the interface).
>
> If we are adding "-l" anyway, is it really necessary? It's not much
> harder to do "git branch -lv" once that is in place.
Well, it will take a while to (re-)take "-l". For the sake of
consistency I wouldn't mind making "--verbose" strictly a "modifier" for
whatever mode/subcommand of the command is going on, even though it
would mean having to type "-v --list" for a long time. In general,
-v/--verbose should always be like that, but is not (e.g. tag -v).
This is in next now but no harm would be done changing it now.
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv4 0/5] mg/branch-list amendment
2011-09-08 9:24 ` Michael J Gruber
@ 2011-09-08 14:25 ` Michael J Gruber
2011-09-08 14:25 ` [PATCHv4 4/5] branch: introduce --list option Michael J Gruber
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
1 sibling, 2 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-09-08 14:25 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano
So, this is what the top 2 commits in mg/branch-list should be replaced
with if we don't let "-v" activate list mode, so that we can have a verbose
option for branch creation later on, i.e.:
git branch -v foo is the verbose version of git branch
Michael J Gruber (2):
branch: introduce --list option
branch: allow pattern arguments
Documentation/git-branch.txt | 17 +++++++++++++----
builtin/branch.c | 35 +++++++++++++++++++++++++++++------
t/t3200-branch.sh | 32 ++++++++++++++++++++++++++++++++
t/t3203-branch-output.sh | 28 ++++++++++++++++++++++++++++
4 files changed, 102 insertions(+), 10 deletions(-)
--
1.7.7.rc0.469.g9eb94
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv4 4/5] branch: introduce --list option
2011-09-08 14:25 ` [PATCHv4 0/5] mg/branch-list amendment Michael J Gruber
@ 2011-09-08 14:25 ` Michael J Gruber
2011-09-08 14:25 ` [PATCHv4 5/5] branch: allow pattern arguments Michael J Gruber
1 sibling, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-09-08 14:25 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano
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
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [PATCHv4 5/5] branch: allow pattern arguments
2011-09-08 14:25 ` [PATCHv4 0/5] mg/branch-list amendment Michael J Gruber
2011-09-08 14:25 ` [PATCHv4 4/5] branch: introduce --list option Michael J Gruber
@ 2011-09-08 14:25 ` Michael J Gruber
1 sibling, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-09-08 14:25 UTC (permalink / raw)
To: git; +Cc: Jeff King, Junio C Hamano
Allow pattern arguments for the list mode just like for git tag -l.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Documentation/git-branch.txt | 8 ++++++--
builtin/branch.c | 24 +++++++++++++++++++++---
t/t3203-branch-output.sh | 23 +++++++++++++++++++++++
3 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 26024b6..2e27ee4 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
'git branch' [--color[=<when>] | --no-color] [-r | -a]
[--list] [-v [--abbrev=<length> | --no-abbrev]]
- [(--merged | --no-merged | --contains) [<commit>]]
+ [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
'git branch' (-m | -M) [<oldbranch>] <newbranch>
'git branch' (-d | -D) [-r] <branchname>...
@@ -22,6 +22,9 @@ 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).
+<pattern> 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 tag is shown.
With `--contains`, shows only the branches that contain the named commit
(in other words, the branches whose tip commits are descendants of the
@@ -112,7 +115,8 @@ OPTIONS
List both remote-tracking branches and local branches.
--list::
- Activate the list mode.
+ Activate the list mode. `git branch <pattern>` would try to create a branch,
+ use `git branch --list <pattern>` to list matching branches.
-v::
--verbose::
diff --git a/builtin/branch.c b/builtin/branch.c
index b17ad26..099c75c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -260,9 +260,22 @@ static char *resolve_symref(const char *src, const char *prefix)
struct append_ref_cb {
struct ref_list *ref_list;
+ const char **pattern;
int ret;
};
+static int match_patterns(const char **pattern, const char *refname)
+{
+ if (!*pattern)
+ return 1; /* no pattern always matches */
+ while (*pattern) {
+ if (!fnmatch(*pattern, refname, 0))
+ return 1;
+ pattern++;
+ }
+ return 0;
+}
+
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{
struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
@@ -297,6 +310,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
if ((kind & ref_list->kinds) == 0)
return 0;
+ if (!match_patterns(cb->pattern, refname))
+ return 0;
+
commit = NULL;
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
commit = lookup_commit_reference_gently(sha1, 1);
@@ -492,7 +508,7 @@ static void show_detached(struct ref_list *ref_list)
}
}
-static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
+static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern)
{
int i;
struct append_ref_cb cb;
@@ -506,6 +522,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
if (merge_filter != NO_FILTER)
init_revisions(&ref_list.revs, NULL);
cb.ref_list = &ref_list;
+ cb.pattern = pattern;
cb.ret = 0;
for_each_rawref(append_ref, &cb);
if (merge_filter != NO_FILTER) {
@@ -523,7 +540,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
detached = (detached && (kinds & REF_LOCAL_BRANCH));
- if (detached)
+ if (detached && match_patterns(pattern, "HEAD"))
show_detached(&ref_list);
for (i = 0; i < ref_list.index; i++) {
@@ -707,7 +724,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (delete)
return delete_branches(argc, argv, delete > 1, kinds);
else if (list)
- return print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+ return print_ref_list(kinds, detached, verbose, abbrev,
+ with_commit, argv);
else if (rename && (argc == 1))
rename_branch(head, argv[0], rename > 1);
else if (rename && (argc == 2))
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 97d10b1..76fe7e0 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -38,6 +38,15 @@ test_expect_success 'git branch --list shows local branches' '
'
cat >expect <<'EOF'
+ branch-one
+ branch-two
+EOF
+test_expect_success 'git branch --list pattern shows matching local branches' '
+ git branch --list branch* >actual &&
+ test_cmp expect actual
+'
+
+cat >expect <<'EOF'
origin/HEAD -> origin/branch-one
origin/branch-one
origin/branch-two
@@ -72,6 +81,20 @@ test_expect_success 'git branch -v shows branch summaries' '
'
cat >expect <<'EOF'
+two
+one
+EOF
+test_expect_success 'git branch --list -v pattern shows branch summaries' '
+ git branch --list -v branch* >tmp &&
+ awk "{print \$NF}" <tmp >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git branch -v pattern does not show branch summaries' '
+ test_must_fail git branch -v branch*
+'
+
+cat >expect <<'EOF'
* (no branch)
branch-one
branch-two
--
1.7.7.rc0.469.g9eb94
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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 21:03 ` Junio C Hamano
2011-09-08 21:11 ` Jeff King
2011-09-08 21:17 ` Junio C Hamano
1 sibling, 2 replies; 77+ messages in thread
From: Junio C Hamano @ 2011-09-08 21:03 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Jeff King, git
Michael J Gruber <git@drmicha.warpmail.net> writes:
> Jeff King venit, vidit, dixit 07.09.2011 21:56:
> ...
>> It does make me a little nervous about the "'git branch -v'
>> automatically means 'git branch --list -v'" patch, though. It closes the
>> door in the future to us being more or less verbose about branch
>> creation details (and while helpful, it creates a slight inconsistency
>> in the interface).
Hasn't 'git branch -v' meant listing in verbose mode for a long enough
time that changing it now would mean a moderately major regression?
At least my copy of v1.7.0 seems to list with "git branch -v".
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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
1 sibling, 0 replies; 77+ messages in thread
From: Jeff King @ 2011-09-08 21:11 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael J Gruber, git
On Thu, Sep 08, 2011 at 02:03:52PM -0700, Junio C Hamano wrote:
> Hasn't 'git branch -v' meant listing in verbose mode for a long enough
> time that changing it now would mean a moderately major regression?
>
> At least my copy of v1.7.0 seems to list with "git branch -v".
No, it will mean the same thing as in v1.7.0; it is not the "-v" which
does it, but the lack of non-option arguments.
Right now, "-v" just means "if we are listing, do it verbosely". And if
you don't specify any non-option arguments, it means "list". So right
now:
git branch ;# list
git branch -v ;# list verbosely
git branch -v foo ;# create branch 'foo', -v does nothing
Michael's proposal was:
git branch -v foo ;# assume verbose list, interpret 'foo' as pattern
which is actually a regression, albeit one that probably doesn't matter
(because "-v" didn't ever do anything with a non-option argument).
Whereas mine is:
git branch -v foo ;# create branch 'foo' verbosely
Which happens to do exactly the same thing as the current behavior,
because there are no verbose messages to add to "git branch". But it
leaves the door open to adding them in the future (and it's consistent
with "git branch -m -v" and "git branch -d -v", both of which could use
"-v" to do their operations more verbosely).
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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
1 sibling, 2 replies; 77+ messages in thread
From: Junio C Hamano @ 2011-09-08 21:17 UTC (permalink / raw)
To: Michael J Gruber, Jeff King; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> Jeff King venit, vidit, dixit 07.09.2011 21:56:
>> ...
>>> It does make me a little nervous about the "'git branch -v'
>>> automatically means 'git branch --list -v'" patch, though. It closes the
>>> door in the future to us being more or less verbose about branch
>>> creation details (and while helpful, it creates a slight inconsistency
>>> in the interface).
>
> Hasn't 'git branch -v' meant listing in verbose mode for a long enough
> time that changing it now would mean a moderately major regression?
>
> At least my copy of v1.7.0 seems to list with "git branch -v".
Ah, nevermind.
As the series is already in 'next', here is what I came up with.
-- >8 --
From: Michael J Gruber <git@drmicha.warpmail.net>
Date: Thu, 8 Sep 2011 14:09:50 -0700
Subject: [PATCH] branch: -v does not automatically imply --list
"branch -v" without other options or parameters still works in the list
mode, but that is not because there is "-v" but because there is no
parameter nor option.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Documentation/git-branch.txt | 6 +++---
builtin/branch.c | 3 +--
t/t3203-branch-output.sh | 8 ++++++--
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 2b8bc84..f46013c 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -21,7 +21,7 @@ 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` and `-v` options (see below).
+activated by the `--list` option (see below).
<pattern> 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 tag is shown.
@@ -120,10 +120,10 @@ OPTIONS
-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.
- `--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 98a420f..099c75c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -712,8 +712,7 @@ 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 &&
- (argc == 0 || (verbose && argc)))
+ if (!delete && !rename && !force_create && argc == 0)
list = 1;
if (!!delete + !!rename + !!force_create + !!list > 1)
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index f2b294b..76fe7e0 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -84,12 +84,16 @@ cat >expect <<'EOF'
two
one
EOF
-test_expect_success 'git branch -v pattern shows branch summaries' '
- git branch -v branch* >tmp &&
+test_expect_success 'git branch --list -v pattern shows branch summaries' '
+ git branch --list -v branch* >tmp &&
awk "{print \$NF}" <tmp >actual &&
test_cmp expect actual
'
+test_expect_success 'git branch -v pattern does not show branch summaries' '
+ test_must_fail git branch -v branch*
+'
+
cat >expect <<'EOF'
* (no branch)
branch-one
--
1.7.7.rc0.188.g3793ac
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
2011-09-08 21:17 ` Junio C Hamano
@ 2011-09-09 1:08 ` Jeff King
2011-09-09 6:54 ` Michael J Gruber
1 sibling, 0 replies; 77+ messages in thread
From: Jeff King @ 2011-09-09 1:08 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael J Gruber, git
On Thu, Sep 08, 2011 at 02:17:24PM -0700, Junio C Hamano wrote:
> "branch -v" without other options or parameters still works in the list
> mode, but that is not because there is "-v" but because there is no
> parameter nor option.
> [...]
> +test_expect_success 'git branch -v pattern does not show branch summaries' '
> + test_must_fail git branch -v branch*
> +'
You might also want to affirm that it does not just fail, but still
creates a branch, like:
test_expect_success 'git branch -v <name> creates a branch' '
git rev-parse HEAD >expect &&
git branch -v foo &&
git rev-parse foo >actual &&
test_cmp expect actual
'
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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
1 sibling, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-09-09 6:54 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git
Junio C Hamano venit, vidit, dixit 08.09.2011 23:17:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Michael J Gruber <git@drmicha.warpmail.net> writes:
>>
>>> Jeff King venit, vidit, dixit 07.09.2011 21:56:
>>> ...
>>>> It does make me a little nervous about the "'git branch -v'
>>>> automatically means 'git branch --list -v'" patch, though. It closes the
>>>> door in the future to us being more or less verbose about branch
>>>> creation details (and while helpful, it creates a slight inconsistency
>>>> in the interface).
>>
>> Hasn't 'git branch -v' meant listing in verbose mode for a long enough
>> time that changing it now would mean a moderately major regression?
>>
>> At least my copy of v1.7.0 seems to list with "git branch -v".
>
> Ah, nevermind.
>
> As the series is already in 'next', here is what I came up with.
I thought you'll rebuild next anyways after 1.7.7, but either way it's
fine. Thanks for holding this series in next long enough to really cook
it (and Jeff for revisiting it), it's much better now, keeping the
(undocumented, but expected) behavior of "git branch -v foo".
>
> -- >8 --
> From: Michael J Gruber <git@drmicha.warpmail.net>
> Date: Thu, 8 Sep 2011 14:09:50 -0700
> Subject: [PATCH] branch: -v does not automatically imply --list
>
> "branch -v" without other options or parameters still works in the list
> mode, but that is not because there is "-v" but because there is no
> parameter nor option.
>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> Documentation/git-branch.txt | 6 +++---
> builtin/branch.c | 3 +--
> t/t3203-branch-output.sh | 8 ++++++--
> 3 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
> index 2b8bc84..f46013c 100644
> --- a/Documentation/git-branch.txt
> +++ b/Documentation/git-branch.txt
> @@ -21,7 +21,7 @@ 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` and `-v` options (see below).
> +activated by the `--list` option (see below).
> <pattern> 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 tag is shown.
> @@ -120,10 +120,10 @@ OPTIONS
>
> -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.
> - `--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 98a420f..099c75c 100644
> --- a/builtin/branch.c
> +++ b/builtin/branch.c
> @@ -712,8 +712,7 @@ 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 &&
> - (argc == 0 || (verbose && argc)))
> + if (!delete && !rename && !force_create && argc == 0)
> list = 1;
>
> if (!!delete + !!rename + !!force_create + !!list > 1)
> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
> index f2b294b..76fe7e0 100755
> --- a/t/t3203-branch-output.sh
> +++ b/t/t3203-branch-output.sh
> @@ -84,12 +84,16 @@ cat >expect <<'EOF'
> two
> one
> EOF
> -test_expect_success 'git branch -v pattern shows branch summaries' '
> - git branch -v branch* >tmp &&
> +test_expect_success 'git branch --list -v pattern shows branch summaries' '
> + git branch --list -v branch* >tmp &&
> awk "{print \$NF}" <tmp >actual &&
> test_cmp expect actual
> '
>
> +test_expect_success 'git branch -v pattern does not show branch summaries' '
> + test_must_fail git branch -v branch*
> +'
> +
> cat >expect <<'EOF'
> * (no branch)
> branch-one
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
2011-09-09 6:54 ` Michael J Gruber
@ 2011-09-09 16:02 ` Junio C Hamano
2011-09-09 19:29 ` Michael J Gruber
0 siblings, 1 reply; 77+ messages in thread
From: Junio C Hamano @ 2011-09-09 16:02 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Jeff King, git
Michael J Gruber <git@drmicha.warpmail.net> writes:
> Junio C Hamano venit, vidit, dixit 08.09.2011 23:17:
>> Ah, nevermind.
>>
>> As the series is already in 'next', here is what I came up with.
>
> I thought you'll rebuild next anyways after 1.7.7, but either way it's
> fine. Thanks for holding this series in next long enough to really cook
> it (and Jeff for revisiting it), it's much better now, keeping the
> (undocumented, but expected) behavior of "git branch -v foo".
Thank *you* for all the work.
I recall Peff had some comments on your new tests last night, by the way.
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
2011-09-09 16:02 ` Junio C Hamano
@ 2011-09-09 19:29 ` Michael J Gruber
2011-09-09 19:30 ` Jeff King
0 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-09-09 19:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git
Junio C Hamano venit, vidit, dixit 09.09.2011 18:02:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> Junio C Hamano venit, vidit, dixit 08.09.2011 23:17:
>>> Ah, nevermind.
>>>
>>> As the series is already in 'next', here is what I came up with.
>>
>> I thought you'll rebuild next anyways after 1.7.7, but either way it's
>> fine. Thanks for holding this series in next long enough to really cook
>> it (and Jeff for revisiting it), it's much better now, keeping the
>> (undocumented, but expected) behavior of "git branch -v foo".
>
> Thank *you* for all the work.
>
> I recall Peff had some comments on your new tests last night, by the way.
>
Yes, we have tests (now) for "-v -d", "-v -m", "-v branch*" and
combinations with --list. Testing "-v foo" for creation would be good
(and belong into t3200). Is there anything to amend?
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv2 4/5] branch: introduce --list option
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
0 siblings, 1 reply; 77+ messages in thread
From: Jeff King @ 2011-09-09 19:30 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Junio C Hamano, git
On Fri, Sep 09, 2011 at 09:29:32PM +0200, Michael J Gruber wrote:
> > I recall Peff had some comments on your new tests last night, by the way.
>
> Yes, we have tests (now) for "-v -d", "-v -m", "-v branch*" and
> combinations with --list. Testing "-v foo" for creation would be good
> (and belong into t3200). Is there anything to amend?
I think my comment was just to add the "-v foo" test.
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCH] t3200: test branch creation with -v
2011-09-09 19:30 ` Jeff King
@ 2011-09-09 19:40 ` Michael J Gruber
2011-09-09 19:43 ` Jeff King
0 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-09-09 19:40 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Make sure that "git branch -v t" creates branch "t".
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
t/t3200-branch.sh | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index c466b20..8381f0c 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -105,6 +105,13 @@ test_expect_success 'git branch -v -d t should work' '
test ! -f .git/refs/heads/t
'
+test_expect_success 'git branch -v t should work' '
+ git branch -v t &&
+ test .git/refs/heads/t &&
+ git branch -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 &&
--
1.7.7.rc0.469.g9eb94
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: test branch creation with -v
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
0 siblings, 2 replies; 77+ messages in thread
From: Jeff King @ 2011-09-09 19:43 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano
On Fri, Sep 09, 2011 at 09:40:59PM +0200, Michael J Gruber wrote:
> +test_expect_success 'git branch -v t should work' '
> + git branch -v t &&
> + test .git/refs/heads/t &&
test -f ?
Also, don't we have test_path_is_file which yields slightly prettier
output (and maybe some portability benefits; I don't remember)?
> + git branch -d t &&
> + test ! -f .git/refs/heads/t
Ditto for 'test_path_is_missing' here.
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: test branch creation with -v
2011-09-09 19:43 ` Jeff King
@ 2011-09-09 19:45 ` Jeff King
2011-09-10 13:29 ` Michael J Gruber
1 sibling, 0 replies; 77+ messages in thread
From: Jeff King @ 2011-09-09 19:45 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano
On Fri, Sep 09, 2011 at 03:43:57PM -0400, Jeff King wrote:
> On Fri, Sep 09, 2011 at 09:40:59PM +0200, Michael J Gruber wrote:
>
> > +test_expect_success 'git branch -v t should work' '
> > + git branch -v t &&
> > + test .git/refs/heads/t &&
>
> test -f ?
Hmm, this also seems to be a problem in the other tests, too.
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: test branch creation with -v
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
1 sibling, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-09-10 13:29 UTC (permalink / raw)
To: Jeff King; +Cc: git, Junio C Hamano
Jeff King venit, vidit, dixit 09.09.2011 21:43:
> On Fri, Sep 09, 2011 at 09:40:59PM +0200, Michael J Gruber wrote:
>
>> +test_expect_success 'git branch -v t should work' ' + git branch
>> -v t && + test .git/refs/heads/t &&
>
> test -f ?
>
> Also, don't we have test_path_is_file which yields slightly prettier
> output (and maybe some portability benefits; I don't remember)?
>
>> + git branch -d t && + test ! -f .git/refs/heads/t
>
> Ditto for 'test_path_is_missing' here.
>
> -Peff
Well, I tried to follow the surrounding style. That t3200 could benefit
from some attention, though, which I did not want to mix in with the
issue at hand.
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: test branch creation with -v
2011-09-10 13:29 ` Michael J Gruber
@ 2011-09-13 3:57 ` Jeff King
2011-09-13 12:12 ` Michael J Gruber
0 siblings, 1 reply; 77+ messages in thread
From: Jeff King @ 2011-09-13 3:57 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano
On Sat, Sep 10, 2011 at 03:29:43PM +0200, Michael J Gruber wrote:
> Jeff King venit, vidit, dixit 09.09.2011 21:43:
> > On Fri, Sep 09, 2011 at 09:40:59PM +0200, Michael J Gruber wrote:
> >
> >> +test_expect_success 'git branch -v t should work' ' + git branch
> >> -v t && + test .git/refs/heads/t &&
> >
> > test -f ?
> >
> > Also, don't we have test_path_is_file which yields slightly prettier
> > output (and maybe some portability benefits; I don't remember)?
> >
> >> + git branch -d t && + test ! -f .git/refs/heads/t
> >
> > Ditto for 'test_path_is_missing' here.
> >
> > -Peff
>
> Well, I tried to follow the surrounding style. That t3200 could benefit
> from some attention, though, which I did not want to mix in with the
> issue at hand.
The "test_path_is_file" thing is style. But not using "test -f" is just
wrong; you are testing "is .git/refs/heads/t an empty string?" which is
useless.
You want this on top of what's in mg/branch-list:
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index c466b20..b513115 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -100,14 +100,14 @@ test_expect_success 'git branch -m q r/q should fail when r exists' '
test_expect_success 'git branch -v -d t should work' '
git branch t &&
- test .git/refs/heads/t &&
+ test -f .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 &&
+ test -f .git/refs/heads/t &&
git branch -v -m t s &&
test ! -f .git/refs/heads/t &&
test -f .git/refs/heads/s &&
@@ -116,7 +116,7 @@ test_expect_success 'git branch -v -m t s should work' '
test_expect_success 'git branch -m -d t s should fail' '
git branch t &&
- test .git/refs/heads/t &&
+ test -f .git/refs/heads/t &&
test_must_fail git branch -m -d t s &&
git branch -d t &&
test ! -f .git/refs/heads/t
@@ -124,7 +124,7 @@ test_expect_success 'git branch -m -d t s should fail' '
test_expect_success 'git branch --list -d t should fail' '
git branch t &&
- test .git/refs/heads/t &&
+ test -f .git/refs/heads/t &&
test_must_fail git branch --list -d t &&
git branch -d t &&
test ! -f .git/refs/heads/t
I suspect you didn't notice the bogosity before because those are just
confirming the precondition that "git branch" actually created the file.
-Peff
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: test branch creation with -v
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
0 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-09-13 12:12 UTC (permalink / raw)
To: Jeff King; +Cc: git, Junio C Hamano
Jeff King venit, vidit, dixit 13.09.2011 05:57:
> On Sat, Sep 10, 2011 at 03:29:43PM +0200, Michael J Gruber wrote:
>
>> Jeff King venit, vidit, dixit 09.09.2011 21:43:
>>> On Fri, Sep 09, 2011 at 09:40:59PM +0200, Michael J Gruber wrote:
>>>
>>>> +test_expect_success 'git branch -v t should work' ' + git branch
>>>> -v t && + test .git/refs/heads/t &&
>>>
>>> test -f ?
>>>
>>> Also, don't we have test_path_is_file which yields slightly prettier
>>> output (and maybe some portability benefits; I don't remember)?
>>>
>>>> + git branch -d t && + test ! -f .git/refs/heads/t
>>>
>>> Ditto for 'test_path_is_missing' here.
>>>
>>> -Peff
>>
>> Well, I tried to follow the surrounding style. That t3200 could benefit
>> from some attention, though, which I did not want to mix in with the
>> issue at hand.
>
> The "test_path_is_file" thing is style. But not using "test -f" is just
> wrong; you are testing "is .git/refs/heads/t an empty string?" which is
> useless.
>
> You want this on top of what's in mg/branch-list:
Yes, sorry. How did I miss that?
I'd prefer your style anyway, but also prefer changing t3200 in one go.
>
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index c466b20..b513115 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -100,14 +100,14 @@ test_expect_success 'git branch -m q r/q should fail when r exists' '
>
> test_expect_success 'git branch -v -d t should work' '
> git branch t &&
> - test .git/refs/heads/t &&
> + test -f .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 &&
> + test -f .git/refs/heads/t &&
> git branch -v -m t s &&
> test ! -f .git/refs/heads/t &&
> test -f .git/refs/heads/s &&
> @@ -116,7 +116,7 @@ test_expect_success 'git branch -v -m t s should work' '
>
> test_expect_success 'git branch -m -d t s should fail' '
> git branch t &&
> - test .git/refs/heads/t &&
> + test -f .git/refs/heads/t &&
> test_must_fail git branch -m -d t s &&
> git branch -d t &&
> test ! -f .git/refs/heads/t
> @@ -124,7 +124,7 @@ test_expect_success 'git branch -m -d t s should fail' '
>
> test_expect_success 'git branch --list -d t should fail' '
> git branch t &&
> - test .git/refs/heads/t &&
> + test -f .git/refs/heads/t &&
> test_must_fail git branch --list -d t &&
> git branch -d t &&
> test ! -f .git/refs/heads/t
>
> I suspect you didn't notice the bogosity before because those are just
> confirming the precondition that "git branch" actually created the file.
>
> -Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCH] t3200: clean up checks for file existence
2011-09-13 12:12 ` Michael J Gruber
@ 2011-09-13 16:13 ` Jeff King
2011-09-13 17:13 ` Junio C Hamano
0 siblings, 1 reply; 77+ messages in thread
From: Jeff King @ 2011-09-13 16:13 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano
This patch uses test_path_is_file and test_path_is_missing
instead of "test -f / ! test -f" checks. The former are more
verbose in case of failure and more precise (e.g., is_missing
will check that the entry is actually missing, not just not
a regular file).
As a bonus, this also fixes a few buggy tests that used
"test foo" instead of "test -f foo", and consequently always
reported success.
Signed-off-by: Jeff King <peff@peff.net>
---
On Tue, Sep 13, 2011 at 02:12:52PM +0200, Michael J Gruber wrote:
> I'd prefer your style anyway, but also prefer changing t3200 in one go.
Here it is, on top of mg/branch-list. The "test without -f" bits could
actually be squashed in to your commits if we really want clean history,
but I don't think it's a big deal.
t/t3200-branch.sh | 50 +++++++++++++++++++++++++-------------------------
1 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index c466b20..3988ec9 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -23,7 +23,7 @@ test_expect_success \
test_expect_success \
'git branch --help should not have created a bogus branch' '
git branch --help </dev/null >/dev/null 2>/dev/null;
- ! test -f .git/refs/heads/--help
+ test_path_is_missing .git/refs/heads/--help
'
test_expect_success 'branch -h in broken repository' '
@@ -39,11 +39,11 @@ test_expect_success 'branch -h in broken repository' '
test_expect_success \
'git branch abc should create a branch' \
- 'git branch abc && test -f .git/refs/heads/abc'
+ 'git branch abc && test_path_is_file .git/refs/heads/abc'
test_expect_success \
'git branch a/b/c should create a branch' \
- 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
+ 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c'
cat >expect <<EOF
$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
@@ -52,15 +52,15 @@ test_expect_success \
'git branch -l d/e/f should create a branch and a log' \
'GIT_COMMITTER_DATE="2005-05-26 23:30" \
git branch -l d/e/f &&
- test -f .git/refs/heads/d/e/f &&
- test -f .git/logs/refs/heads/d/e/f &&
+ test_path_is_file .git/refs/heads/d/e/f &&
+ test_path_is_file .git/logs/refs/heads/d/e/f &&
test_cmp expect .git/logs/refs/heads/d/e/f'
test_expect_success \
'git branch -d d/e/f should delete a branch and a log' \
'git branch -d d/e/f &&
- test ! -f .git/refs/heads/d/e/f &&
- test ! -f .git/logs/refs/heads/d/e/f'
+ test_path_is_missing .git/refs/heads/d/e/f &&
+ test_path_is_missing .git/logs/refs/heads/d/e/f'
test_expect_success \
'git branch j/k should work after branch j has been deleted' \
@@ -78,13 +78,13 @@ test_expect_success \
'git branch -m m m/m should work' \
'git branch -l m &&
git branch -m m m/m &&
- test -f .git/logs/refs/heads/m/m'
+ test_path_is_file .git/logs/refs/heads/m/m'
test_expect_success \
'git branch -m n/n n should work' \
'git branch -l n/n &&
git branch -m n/n n
- test -f .git/logs/refs/heads/n'
+ test_path_is_file .git/logs/refs/heads/n'
test_expect_success 'git branch -m o/o o should fail when o/p exists' '
git branch o/o &&
@@ -100,34 +100,34 @@ test_expect_success 'git branch -m q r/q should fail when r exists' '
test_expect_success 'git branch -v -d t should work' '
git branch t &&
- test .git/refs/heads/t &&
+ test_path_is_file .git/refs/heads/t &&
git branch -v -d t &&
- test ! -f .git/refs/heads/t
+ test_path_is_missing .git/refs/heads/t
'
test_expect_success 'git branch -v -m t s should work' '
git branch t &&
- test .git/refs/heads/t &&
+ test_path_is_file .git/refs/heads/t &&
git branch -v -m t s &&
- test ! -f .git/refs/heads/t &&
- test -f .git/refs/heads/s &&
+ test_path_is_missing .git/refs/heads/t &&
+ test_path_is_file .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_path_is_file .git/refs/heads/t &&
test_must_fail git branch -m -d t s &&
git branch -d t &&
- test ! -f .git/refs/heads/t
+ test_path_is_missing .git/refs/heads/t
'
test_expect_success 'git branch --list -d t should fail' '
git branch t &&
- test .git/refs/heads/t &&
+ test_path_is_file .git/refs/heads/t &&
test_must_fail git branch --list -d t &&
git branch -d t &&
- test ! -f .git/refs/heads/t
+ test_path_is_missing .git/refs/heads/t
'
mv .git/config .git/config-saved
@@ -144,12 +144,12 @@ git config branch.s/s.dummy Hello
test_expect_success \
'git branch -m s/s s should work when s/t is deleted' \
'git branch -l s/s &&
- test -f .git/logs/refs/heads/s/s &&
+ test_path_is_file .git/logs/refs/heads/s/s &&
git branch -l s/t &&
- test -f .git/logs/refs/heads/s/t &&
+ test_path_is_file .git/logs/refs/heads/s/t &&
git branch -d s/t &&
git branch -m s/s s &&
- test -f .git/logs/refs/heads/s'
+ test_path_is_file .git/logs/refs/heads/s'
test_expect_success 'config information was renamed, too' \
"test $(git config branch.s.dummy) = Hello &&
@@ -160,8 +160,8 @@ test_expect_success 'renaming a symref is not allowed' \
git symbolic-ref refs/heads/master2 refs/heads/master &&
test_must_fail git branch -m master2 master3 &&
git symbolic-ref refs/heads/master2 &&
- test -f .git/refs/heads/master &&
- ! test -f .git/refs/heads/master3
+ test_path_is_file .git/refs/heads/master &&
+ test_path_is_missing .git/refs/heads/master3
'
test_expect_success SYMLINKS \
@@ -270,8 +270,8 @@ test_expect_success \
'git checkout -b g/h/i -l should create a branch and a log' \
'GIT_COMMITTER_DATE="2005-05-26 23:30" \
git checkout -b g/h/i -l master &&
- test -f .git/refs/heads/g/h/i &&
- test -f .git/logs/refs/heads/g/h/i &&
+ test_path_is_file .git/refs/heads/g/h/i &&
+ test_path_is_file .git/logs/refs/heads/g/h/i &&
test_cmp expect .git/logs/refs/heads/g/h/i'
test_expect_success 'checkout -b makes reflog by default' '
--
1.7.7.rc1.2.gb2409
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: clean up checks for file existence
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
0 siblings, 1 reply; 77+ messages in thread
From: Junio C Hamano @ 2011-09-13 17:13 UTC (permalink / raw)
To: Jeff King; +Cc: Michael J Gruber, git
Jeff King <peff@peff.net> writes:
> Here it is, on top of mg/branch-list. The "test without -f" bits could
> actually be squashed in to your commits if we really want clean history,
> but I don't think it's a big deal.
Thanks.
In the longer term, we might want to update these tests further so that
they do not fail when implementation is updated not to write loose refs,
e.g.
> test_expect_success \
> 'git branch abc should create a branch' \
> - 'git branch abc && test -f .git/refs/heads/abc'
> + 'git branch abc && test_path_is_file .git/refs/heads/abc'
git branch abc && git show-ref -q --verify refs/heads/abc
But this patch is about correctness first, so I'll queue it as-is.
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCH] t3200: clean up checks for file existence
2011-09-13 17:13 ` Junio C Hamano
@ 2011-09-13 17:16 ` Jeff King
0 siblings, 0 replies; 77+ messages in thread
From: Jeff King @ 2011-09-13 17:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael J Gruber, git
On Tue, Sep 13, 2011 at 10:13:56AM -0700, Junio C Hamano wrote:
> In the longer term, we might want to update these tests further so that
> they do not fail when implementation is updated not to write loose refs,
> e.g.
Yeah, I noticed that, too, but figured to leave it for when such a
change came about (which is probably going to need to fix tests
everywhere, not just here). I'm happy to fix this area now, though, if
you want.
-Peff
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv2 5/5] branch: allow pattern arguments
2011-08-26 14:05 ` [PATCHv2 0/5] " Michael J Gruber
` (3 preceding siblings ...)
2011-08-26 14:05 ` [PATCHv2 4/5] branch: introduce --list option Michael J Gruber
@ 2011-08-26 14:05 ` 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
5 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-26 14:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Allow pattern arguments for the list mode just like for git tag -l.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Documentation/git-branch.txt | 8 ++++++--
builtin/branch.c | 24 +++++++++++++++++++++---
t/t3203-branch-output.sh | 10 ++++++++++
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index ac278fb..2b8bc84 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
'git branch' [--color[=<when>] | --no-color] [-r | -a]
[--list] [-v [--abbrev=<length> | --no-abbrev]]
- [(--merged | --no-merged | --contains) [<commit>]]
+ [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
'git branch' (-m | -M) [<oldbranch>] <newbranch>
'git branch' (-d | -D) [-r] <branchname>...
@@ -22,6 +22,9 @@ 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` and `-v` options (see below).
+<pattern> 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 tag is shown.
With `--contains`, shows only the branches that contain the named commit
(in other words, the branches whose tip commits are descendants of the
@@ -112,7 +115,8 @@ OPTIONS
List both remote-tracking branches and local branches.
--list::
- Activate the list mode.
+ Activate the list mode. `git branch <pattern>` would try to create a branch,
+ use `git branch --list <pattern>` to list matching branches.
-v::
--verbose::
diff --git a/builtin/branch.c b/builtin/branch.c
index 4a33b07..e6bef49 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -260,9 +260,22 @@ static char *resolve_symref(const char *src, const char *prefix)
struct append_ref_cb {
struct ref_list *ref_list;
+ const char **pattern;
int ret;
};
+static int match_patterns(const char **pattern, const char *refname)
+{
+ if (!*pattern)
+ return 1; /* no pattern always matches */
+ while (*pattern) {
+ if (!fnmatch(*pattern, refname, 0))
+ return 1;
+ pattern++;
+ }
+ return 0;
+}
+
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{
struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
@@ -297,6 +310,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
if ((kind & ref_list->kinds) == 0)
return 0;
+ if (!match_patterns(cb->pattern, refname))
+ return 0;
+
commit = NULL;
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
commit = lookup_commit_reference_gently(sha1, 1);
@@ -492,7 +508,7 @@ static void show_detached(struct ref_list *ref_list)
}
}
-static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
+static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern)
{
int i;
struct append_ref_cb cb;
@@ -506,6 +522,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
if (merge_filter != NO_FILTER)
init_revisions(&ref_list.revs, NULL);
cb.ref_list = &ref_list;
+ cb.pattern = pattern;
cb.ret = 0;
for_each_rawref(append_ref, &cb);
if (merge_filter != NO_FILTER) {
@@ -523,7 +540,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
detached = (detached && (kinds & REF_LOCAL_BRANCH));
- if (detached)
+ if (detached && match_patterns(pattern, "HEAD"))
show_detached(&ref_list);
for (i = 0; i < ref_list.index; i++) {
@@ -701,7 +718,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (delete)
return delete_branches(argc, argv, delete > 1, kinds);
else if (list)
- return print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+ return print_ref_list(kinds, detached, verbose, abbrev,
+ with_commit, argv);
else if (rename && (argc == 1))
rename_branch(head, argv[0], rename > 1);
else if (rename && (argc == 2))
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 61e095c..f2b294b 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -81,6 +81,16 @@ test_expect_success 'git branch -v shows branch summaries' '
'
cat >expect <<'EOF'
+two
+one
+EOF
+test_expect_success 'git branch -v pattern shows branch summaries' '
+ git branch -v branch* >tmp &&
+ awk "{print \$NF}" <tmp >actual &&
+ test_cmp expect actual
+'
+
+cat >expect <<'EOF'
* (no branch)
branch-one
branch-two
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [PATCHv3 0/5] patterns for branch list
2011-08-26 14:05 ` [PATCHv2 0/5] " Michael J Gruber
` (4 preceding siblings ...)
2011-08-26 14:05 ` [PATCHv2 5/5] branch: allow pattern arguments Michael J Gruber
@ 2011-08-28 14:54 ` Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 1/5] t6040: test branch -vv Michael J Gruber
` (4 more replies)
5 siblings, 5 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:54 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
v3 has reworded commit messages for 2,3,4 and tests for combinations
of branch options in 4, as suggested.
No code changes (besides the additional tests in 4).
Michael J Gruber (5):
t6040: test branch -vv
git-tag: introduce long forms for the options
git-branch: introduce missing long forms for the options
branch: introduce --list option
branch: allow pattern arguments
Documentation/git-branch.txt | 20 +++++++++++++++--
Documentation/git-tag.txt | 8 +++++++
builtin/branch.c | 46 +++++++++++++++++++++++++++++++----------
builtin/tag.c | 16 +++++++-------
t/t3200-branch.sh | 32 +++++++++++++++++++++++++++++
t/t3203-branch-output.sh | 24 +++++++++++++++++++++
t/t6040-tracking-info.sh | 16 ++++++++++++++
7 files changed, 140 insertions(+), 22 deletions(-)
--
1.7.6.845.gc3c05
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv3 1/5] t6040: test branch -vv
2011-08-28 14:54 ` [PATCHv3 0/5] patterns for branch list Michael J Gruber
@ 2011-08-28 14:54 ` Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 2/5] git-tag: introduce long forms for the options Michael J Gruber
` (3 subsequent siblings)
4 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:54 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
t6040 has a test for 'git branch -v' but not for 'git branch -vv'.
Add one.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
t/t6040-tracking-info.sh | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 19de5b1..19272bc 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -51,6 +51,22 @@ test_expect_success 'branch -v' '
test_i18ncmp expect actual
'
+cat >expect <<\EOF
+b1 origin/master: ahead 1, behind 1
+b2 origin/master: ahead 1, behind 1
+b3 origin/master: behind 1
+b4 origin/master: ahead 2
+EOF
+
+test_expect_success 'branch -vv' '
+ (
+ cd test &&
+ git branch -vv
+ ) |
+ sed -n -e "$script" >actual &&
+ test_i18ncmp expect actual
+'
+
test_expect_success 'checkout' '
(
cd test && git checkout b1
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [PATCHv3 2/5] git-tag: introduce long forms for the options
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 ` Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 3/5] git-branch: introduce missing " Michael J Gruber
` (2 subsequent siblings)
4 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:54 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Long forms are better to memorize and more reliably uniform across
commands.
Design notes:
-u,--local-user is named following the analogous gnupg option.
-l,--list is not an argument taking option but a mode switch.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Documentation/git-tag.txt | 8 ++++++++
builtin/tag.c | 16 ++++++++--------
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index fb1c0ac..c83cb13 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -43,12 +43,15 @@ GnuPG key for signing.
OPTIONS
-------
-a::
+--annotate::
Make an unsigned, annotated tag object
-s::
+--sign::
Make a GPG-signed tag, using the default e-mail address's key
-u <key-id>::
+--local-user=<key-id>::
Make a GPG-signed tag, using the given key
-f::
@@ -56,9 +59,11 @@ OPTIONS
Replace an existing tag with the given name (instead of failing)
-d::
+--delete::
Delete existing tags with the given names.
-v::
+--verify::
Verify the gpg signature of the given tag names.
-n<num>::
@@ -69,6 +74,7 @@ OPTIONS
If the tag is not annotated, the commit message is displayed instead.
-l <pattern>::
+--list <pattern>::
List tags with names that match the given pattern (or all if no
pattern is given). Running "git tag" without arguments also
lists all tags. The pattern is a shell wildcard (i.e., matched
@@ -79,6 +85,7 @@ OPTIONS
Only list tags which contain the specified commit.
-m <msg>::
+--message=<msg>::
Use the given tag message (instead of prompting).
If multiple `-m` options are given, their values are
concatenated as separate paragraphs.
@@ -86,6 +93,7 @@ OPTIONS
is given.
-F <file>::
+--file=<file>::
Take the tag message from the given file. Use '-' to
read the message from the standard input.
Implies `-a` if none of `-a`, `-s`, or `-u <key-id>`
diff --git a/builtin/tag.c b/builtin/tag.c
index 667515e..9d89616 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -429,21 +429,21 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct msg_arg msg = { 0, STRBUF_INIT };
struct commit_list *with_commit = NULL;
struct option options[] = {
- OPT_BOOLEAN('l', NULL, &list, "list tag names"),
+ OPT_BOOLEAN('l', "list", &list, "list tag names"),
{ OPTION_INTEGER, 'n', NULL, &lines, "n",
"print <n> lines of each tag message",
PARSE_OPT_OPTARG, NULL, 1 },
- OPT_BOOLEAN('d', NULL, &delete, "delete tags"),
- OPT_BOOLEAN('v', NULL, &verify, "verify tags"),
+ OPT_BOOLEAN('d', "delete", &delete, "delete tags"),
+ OPT_BOOLEAN('v', "verify", &verify, "verify tags"),
OPT_GROUP("Tag creation options"),
- OPT_BOOLEAN('a', NULL, &annotate,
+ OPT_BOOLEAN('a', "annotate", &annotate,
"annotated tag, needs a message"),
- OPT_CALLBACK('m', NULL, &msg, "message",
+ OPT_CALLBACK('m', "message", &msg, "message",
"tag message", parse_msg_arg),
- OPT_FILENAME('F', NULL, &msgfile, "read message from file"),
- OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
- OPT_STRING('u', NULL, &keyid, "key-id",
+ OPT_FILENAME('F', "file", &msgfile, "read message from file"),
+ OPT_BOOLEAN('s', "sign", &sign, "annotated and GPG-signed tag"),
+ OPT_STRING('u', "local-user", &keyid, "key-id",
"use another key to sign the tag"),
OPT__FORCE(&force, "replace the tag if exists"),
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [PATCHv3 3/5] git-branch: introduce missing long forms for the options
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 ` Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 4/5] branch: introduce --list option Michael J Gruber
2011-08-28 14:54 ` [PATCHv3 5/5] branch: allow pattern arguments Michael J Gruber
4 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:54 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Long forms are better to memorize and more reliably uniform across
commands.
Names follow precedents, e.g. "git log --remotes".
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
I'm somewhat torn between --move and --rename for -m. We have no real precedent
besides "git remote rename".
I left out -M and -D because I feel they should really be -m -f resp. -d -f.
---
Documentation/git-branch.txt | 5 +++++
builtin/branch.c | 10 +++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 507b8d0..4c64ac9 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -64,6 +64,7 @@ way to clean up all obsolete remote-tracking branches.
OPTIONS
-------
-d::
+--delete::
Delete a branch. The branch must be fully merged in its
upstream branch, or in `HEAD` if no upstream was set with
`--track` or `--set-upstream`.
@@ -72,6 +73,7 @@ OPTIONS
Delete a branch irrespective of its merged status.
-l::
+--create-reflog::
Create the branch's reflog. This activates recording of
all changes made to the branch ref, enabling use of date
based sha1 expressions such as "<branchname>@\{yesterday}".
@@ -84,6 +86,7 @@ OPTIONS
already. Without `-f` 'git branch' refuses to change an existing branch.
-m::
+--move::
Move/rename a branch and the corresponding reflog.
-M::
@@ -100,9 +103,11 @@ OPTIONS
Same as `--color=never`.
-r::
+--remotes::
List or delete (if used with -d) the remote-tracking branches.
-a::
+--all::
List both remote-tracking branches and local branches.
-v::
diff --git a/builtin/branch.c b/builtin/branch.c
index aa705a0..94e41ae 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -624,7 +624,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_SET_INT( 0, "set-upstream", &track, "change upstream info",
BRANCH_TRACK_OVERRIDE),
OPT__COLOR(&branch_use_color, "use colored output"),
- OPT_SET_INT('r', NULL, &kinds, "act on remote-tracking branches",
+ OPT_SET_INT('r', "remotes", &kinds, "act on remote-tracking branches",
REF_REMOTE_BRANCH),
{
OPTION_CALLBACK, 0, "contains", &with_commit, "commit",
@@ -641,13 +641,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT__ABBREV(&abbrev),
OPT_GROUP("Specific git-branch actions:"),
- OPT_SET_INT('a', NULL, &kinds, "list both remote-tracking and local branches",
+ OPT_SET_INT('a', "all", &kinds, "list both remote-tracking and local branches",
REF_REMOTE_BRANCH | REF_LOCAL_BRANCH),
- OPT_BIT('d', NULL, &delete, "delete fully merged branch", 1),
+ OPT_BIT('d', "delete", &delete, "delete fully merged branch", 1),
OPT_BIT('D', NULL, &delete, "delete branch (even if not merged)", 2),
- OPT_BIT('m', NULL, &rename, "move/rename a branch and its reflog", 1),
+ 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('l', NULL, &reflog, "create the branch's reflog"),
+ OPT_BOOLEAN('l', "create-reflog", &reflog, "create the branch's reflog"),
OPT__FORCE(&force_create, "force creation (when already exists)"),
{
OPTION_CALLBACK, 0, "no-merged", &merge_filter_ref,
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* [PATCHv3 4/5] branch: introduce --list option
2011-08-28 14:54 ` [PATCHv3 0/5] patterns for branch list Michael J Gruber
` (2 preceding siblings ...)
2011-08-28 14:54 ` [PATCHv3 3/5] git-branch: introduce missing " Michael J Gruber
@ 2011-08-28 14:54 ` Michael J Gruber
2011-08-29 5:55 ` Junio C Hamano
2011-08-28 14:54 ` [PATCHv3 5/5] branch: allow pattern arguments Michael J Gruber
4 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:54 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
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>
---
Documentation/git-branch.txt | 9 +++++++--
builtin/branch.c | 12 +++++++++---
t/t3200-branch.sh | 32 ++++++++++++++++++++++++++++++++
t/t3203-branch-output.sh | 14 ++++++++++++++
4 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 4c64ac9..ac278fb 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` 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
@@ -110,11 +111,15 @@ 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
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 94e41ae..4a33b07 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -608,7 +608,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;
@@ -647,6 +647,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)"),
{
@@ -686,7 +687,12 @@ 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 || (verbose && argc)))
+ list = 1;
+
+ if (!!delete + !!rename + !!force_create + !!list > 1)
usage_with_options(builtin_branch_usage, options);
if (abbrev == -1)
@@ -694,7 +700,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 cb6458d..931373c 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
+'
+
test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
git branch bar &&
git checkout -b foo &&
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 6b7c118..61e095c 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -32,6 +32,20 @@ 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'
+ branch-one
+ branch-two
+EOF
+test_expect_success 'git branch --list pattern shows matching local branches' '
+ git branch --list branch* >actual &&
+ test_cmp expect actual
+'
+
cat >expect <<'EOF'
origin/HEAD -> origin/branch-one
origin/branch-one
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv3 4/5] branch: introduce --list option
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
0 siblings, 1 reply; 77+ messages in thread
From: Junio C Hamano @ 2011-08-29 5:55 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Jeff King
Michael J Gruber <git@drmicha.warpmail.net> writes:
> +test_expect_success 'git branch --list shows local branches' '
> + git branch --list >actual &&
> + test_cmp expect actual
> +'
> +
> +cat >expect <<'EOF'
> + branch-one
> + branch-two
> +EOF
> +test_expect_success 'git branch --list pattern shows matching local branches' '
> + git branch --list branch* >actual &&
> + test_cmp expect actual
> +'
Does this one exclude the "* master" entry at this stage in the series?
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv3 4/5] branch: introduce --list option
2011-08-29 5:55 ` Junio C Hamano
@ 2011-08-29 6:35 ` Michael J Gruber
2011-08-29 6:51 ` Junio C Hamano
0 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-29 6:35 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King
Junio C Hamano venit, vidit, dixit 29.08.2011 07:55:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> +test_expect_success 'git branch --list shows local branches' '
>> + git branch --list >actual &&
>> + test_cmp expect actual
>> +'
>> +
>> +cat >expect <<'EOF'
>> + branch-one
>> + branch-two
>> +EOF
>> +test_expect_success 'git branch --list pattern shows matching local branches' '
>> + git branch --list branch* >actual &&
>> + test_cmp expect actual
>> +'
>
> Does this one exclude the "* master" entry at this stage in the series?
Sheesh, that rebasing mistake (flipping the order of 4 and 5) was
present in v2 already. Only recently I learned about rebase-i's "exec"
and have to make it a habit to use it for step-by-step series testing.
Sorry, I'll send out v3 a bit later when I see that there are no more
comments (and a full step-by-step series test has passed).
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv3 4/5] branch: introduce --list option
2011-08-29 6:35 ` Michael J Gruber
@ 2011-08-29 6:51 ` Junio C Hamano
0 siblings, 0 replies; 77+ messages in thread
From: Junio C Hamano @ 2011-08-29 6:51 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Jeff King
Michael J Gruber <git@drmicha.warpmail.net> writes:
> Sheesh, that rebasing mistake (flipping the order of 4 and 5) was
> present in v2 already. Only recently I learned about rebase-i's "exec"
> and have to make it a habit to use it for step-by-step series testing.
That's Ok. Locally moved the offending part of the test to 5 when
applying.
Thanks.
^ permalink raw reply [flat|nested] 77+ messages in thread
* [PATCHv3 5/5] branch: allow pattern arguments
2011-08-28 14:54 ` [PATCHv3 0/5] patterns for branch list Michael J Gruber
` (3 preceding siblings ...)
2011-08-28 14:54 ` [PATCHv3 4/5] branch: introduce --list option Michael J Gruber
@ 2011-08-28 14:54 ` Michael J Gruber
2011-09-06 13:10 ` Michael Schubert
4 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-08-28 14:54 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King
Allow pattern arguments for the list mode just like for git tag -l.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Documentation/git-branch.txt | 8 ++++++--
builtin/branch.c | 24 +++++++++++++++++++++---
t/t3203-branch-output.sh | 10 ++++++++++
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index ac278fb..2b8bc84 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
'git branch' [--color[=<when>] | --no-color] [-r | -a]
[--list] [-v [--abbrev=<length> | --no-abbrev]]
- [(--merged | --no-merged | --contains) [<commit>]]
+ [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
'git branch' (-m | -M) [<oldbranch>] <newbranch>
'git branch' (-d | -D) [-r] <branchname>...
@@ -22,6 +22,9 @@ 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` and `-v` options (see below).
+<pattern> 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 tag is shown.
With `--contains`, shows only the branches that contain the named commit
(in other words, the branches whose tip commits are descendants of the
@@ -112,7 +115,8 @@ OPTIONS
List both remote-tracking branches and local branches.
--list::
- Activate the list mode.
+ Activate the list mode. `git branch <pattern>` would try to create a branch,
+ use `git branch --list <pattern>` to list matching branches.
-v::
--verbose::
diff --git a/builtin/branch.c b/builtin/branch.c
index 4a33b07..e6bef49 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -260,9 +260,22 @@ static char *resolve_symref(const char *src, const char *prefix)
struct append_ref_cb {
struct ref_list *ref_list;
+ const char **pattern;
int ret;
};
+static int match_patterns(const char **pattern, const char *refname)
+{
+ if (!*pattern)
+ return 1; /* no pattern always matches */
+ while (*pattern) {
+ if (!fnmatch(*pattern, refname, 0))
+ return 1;
+ pattern++;
+ }
+ return 0;
+}
+
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{
struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
@@ -297,6 +310,9 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
if ((kind & ref_list->kinds) == 0)
return 0;
+ if (!match_patterns(cb->pattern, refname))
+ return 0;
+
commit = NULL;
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
commit = lookup_commit_reference_gently(sha1, 1);
@@ -492,7 +508,7 @@ static void show_detached(struct ref_list *ref_list)
}
}
-static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit)
+static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern)
{
int i;
struct append_ref_cb cb;
@@ -506,6 +522,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
if (merge_filter != NO_FILTER)
init_revisions(&ref_list.revs, NULL);
cb.ref_list = &ref_list;
+ cb.pattern = pattern;
cb.ret = 0;
for_each_rawref(append_ref, &cb);
if (merge_filter != NO_FILTER) {
@@ -523,7 +540,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
detached = (detached && (kinds & REF_LOCAL_BRANCH));
- if (detached)
+ if (detached && match_patterns(pattern, "HEAD"))
show_detached(&ref_list);
for (i = 0; i < ref_list.index; i++) {
@@ -701,7 +718,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (delete)
return delete_branches(argc, argv, delete > 1, kinds);
else if (list)
- return print_ref_list(kinds, detached, verbose, abbrev, with_commit);
+ return print_ref_list(kinds, detached, verbose, abbrev,
+ with_commit, argv);
else if (rename && (argc == 1))
rename_branch(head, argv[0], rename > 1);
else if (rename && (argc == 2))
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 61e095c..f2b294b 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -81,6 +81,16 @@ test_expect_success 'git branch -v shows branch summaries' '
'
cat >expect <<'EOF'
+two
+one
+EOF
+test_expect_success 'git branch -v pattern shows branch summaries' '
+ git branch -v branch* >tmp &&
+ awk "{print \$NF}" <tmp >actual &&
+ test_cmp expect actual
+'
+
+cat >expect <<'EOF'
* (no branch)
branch-one
branch-two
--
1.7.6.845.gc3c05
^ permalink raw reply related [flat|nested] 77+ messages in thread
* Re: [PATCHv3 5/5] branch: allow pattern arguments
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
0 siblings, 1 reply; 77+ messages in thread
From: Michael Schubert @ 2011-09-06 13:10 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git, Junio C Hamano, Jeff King
On 08/28/2011 04:54 PM, Michael J Gruber wrote:
> +static int match_patterns(const char **pattern, const char *refname)
> +{
> + if (!*pattern)
> + return 1; /* no pattern always matches */
> + while (*pattern) {
> + if (!fnmatch(*pattern, refname, 0))
> + return 1;
> + pattern++;
> + }
> + return 0;
> +}
Nitpick: maybe builtin/branch.c and builtin/tag.c could share match_pattern().?
A second thought: the printed "remotes/" prefix could be confusing for users,
since it seems to be part of the refname. For example:
$ git branch -a
* master
maint
man
remotes/origin/master
remotes/origin/maint
remotes/origin/man
$ git branch -a --list remotes/origin*
[no output]
but
$ git branch -a --list origin*
remotes/origin/master
remotes/origin/maint
remotes/origin/man
(Sorry in case I missed that) What's the reason you decided --list to show local
branches only? Maybe --list could show all refnames without any extra prefix.?
Thanks.
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv3 5/5] branch: allow pattern arguments
2011-09-06 13:10 ` Michael Schubert
@ 2011-09-06 14:21 ` Michael J Gruber
2011-09-06 14:26 ` Sverre Rabbelier
0 siblings, 1 reply; 77+ messages in thread
From: Michael J Gruber @ 2011-09-06 14:21 UTC (permalink / raw)
To: Michael Schubert; +Cc: git, Junio C Hamano, Jeff King
Michael Schubert venit, vidit, dixit 06.09.2011 15:10:
> On 08/28/2011 04:54 PM, Michael J Gruber wrote:
>> +static int match_patterns(const char **pattern, const char *refname)
>> +{
>> + if (!*pattern)
>> + return 1; /* no pattern always matches */
>> + while (*pattern) {
>> + if (!fnmatch(*pattern, refname, 0))
>> + return 1;
>> + pattern++;
>> + }
>> + return 0;
>> +}
>
> Nitpick: maybe builtin/branch.c and builtin/tag.c could share match_pattern().?
I think all commands which list refs should share code - for-each-ref,
branch, tag, replace. I suggest to unify log and for-each-ref-formats
first, the unify ref listers.
> A second thought: the printed "remotes/" prefix could be confusing for users,
> since it seems to be part of the refname. For example:
>
> $ git branch -a
> * master
> maint
> man
> remotes/origin/master
> remotes/origin/maint
> remotes/origin/man
>
> $ git branch -a --list remotes/origin*
> [no output]
>
> but
>
> $ git branch -a --list origin*
> remotes/origin/master
> remotes/origin/maint
> remotes/origin/man
>
> (Sorry in case I missed that) What's the reason you decided --list to show local
> branches only? Maybe --list could show all refnames without any extra prefix.?
I didn't decide anything here. "git branch" lists all local branches and
has been doing that forever, and "--list" is and should be a noop
without a pattern. That was the idea: -r/-a select refnames,
--list/-v/-vv activate the list mode(s), and the pattern is matched
against the selected refs.
(This is one reason why I didn't want it to be named --glob - the
pattern is a filter, not a selector.)
That being said, I find the fact that "-a --list remotes/origin/*" does
not match anything somewhat disconcerting, although it fits in with the
general idea of "git branch": it deals with branch names, not ref names.
Have you ever tried to delete a remote branch?
git branch -r -d origin/maint # workee
git branch -r -d remotes/origin/maint # no workee
Without -r, it doesn't work either.
So, the way it is it fits in with how "git branch" works, and is
different from for-each-ref (and rev-list --glob). I don't like it,
because you may have a local branch origin/maint (i.e.
refs/heads/origin/maint) which you can't distinguish from the remote
branch by a pattern, only by using or not using -r. But it's the same as
with "git branch -d", really.
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv3 5/5] branch: allow pattern arguments
2011-09-06 14:21 ` Michael J Gruber
@ 2011-09-06 14:26 ` Sverre Rabbelier
2011-09-06 16:11 ` Michael J Gruber
0 siblings, 1 reply; 77+ messages in thread
From: Sverre Rabbelier @ 2011-09-06 14:26 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Michael Schubert, git, Junio C Hamano, Jeff King
Heya,
On Tue, Sep 6, 2011 at 16:21, Michael J Gruber <git@drmicha.warpmail.net> wrote:
> Have you ever tried to delete a remote branch?
>
> git branch -r -d origin/maint # workee
> git branch -r -d remotes/origin/maint # no workee
>
> Without -r, it doesn't work either.
Heh, I read this as "worktree" / "no worktree" at least 4 times.
--
Cheers,
Sverre Rabbelier
^ permalink raw reply [flat|nested] 77+ messages in thread
* Re: [PATCHv3 5/5] branch: allow pattern arguments
2011-09-06 14:26 ` Sverre Rabbelier
@ 2011-09-06 16:11 ` Michael J Gruber
0 siblings, 0 replies; 77+ messages in thread
From: Michael J Gruber @ 2011-09-06 16:11 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: Michael Schubert, git, Junio C Hamano, Jeff King
Sverre Rabbelier venit, vidit, dixit 06.09.2011 16:26:
> Heya,
>
> On Tue, Sep 6, 2011 at 16:21, Michael J Gruber <git@drmicha.warpmail.net> wrote:
>> Have you ever tried to delete a remote branch?
>>
>> git branch -r -d origin/maint # workee
>> git branch -r -d remotes/origin/maint # no workee
>>
>> Without -r, it doesn't work either.
>
> Heh, I read this as "worktree" / "no worktree" at least 4 times.
>
Yes, our require_work_tree should really be renamed to
no_worktree_no_workee
The beauty of pidgin english ;)
Michael
^ permalink raw reply [flat|nested] 77+ messages in thread