Various changes to the "tag" command & related
v4 cover Various changes to the "tag" command & related
Hopefully the final version. This is exactly like v3 except for a couple of minor changes (and rebased on the latest upstream master):
Ævar Arnfjörð Bjarmason (16):
tag doc: move the description of --[no-]merged earlier tag doc: split up the --[no-]merged documentation tag doc: reword --[no-]merged to talk about commits, not tips
ref-filter: make combining --merged & --no-merged an error
ref-filter: add test for --contains on a non-commit
tag: remove a TODO item from the test suite
tag tests: fix a typo in a test description
for-each-ref: partly change <object> to <commit> in help
tag: add more incompatibles mode tests
Clarified in the commit message what code in builtin/tag.c we're trying to test here.
parse-options: add OPT_NONEG to the "contains" option
tag: change misleading --list <pattern> documentation
Use the same phrasing as Junio's "branch doc: update description for --list" does when describing "git tag --list".
tag: implicitly supply --list given another list-like option
tag: change --point-at to default to HEAD
ref-filter: add --no-contains option to tag/branch/for-each-ref
ref-filter: reflow recently changed branch/tag/for-each-ref docs
tag: add tests for --with and --without
Documentation/git-branch.txt | 33 +++-- Documentation/git-for-each-ref.txt | 12 +- Documentation/git-tag.txt | 59 +++++--- builtin/branch.c | 5 +- builtin/for-each-ref.c | 5 +- builtin/tag.c | 27 ++-- contrib/completion/git-completion.bash | 4 +- parse-options.h | 6 +- ref-filter.c | 30 +++- ref-filter.h | 1 + t/t3200-branch.sh | 4 + t/t3201-branch-contains.sh | 61 +++++++- t/t6302-for-each-ref-filter.sh | 20 +++ t/t7004-tag.sh | 245 +++++++++++++++++++++++++++++++-- 14 files changed, 440 insertions(+), 72 deletions(-)
Signature · 1 line
2.11.0
PATCH v4 1/16 tag doc: move the description of --[no-]merged earlier
Move the documentation for the --merged & --no-merged options earlier in the documentation, to sit along the other switches, and right next to the similar --contains and --points-at switches.
It makes more sense to group the options together, not have some options after the like of <tagname>, <object>, <format> etc.
This was originally put there when the --merged & --no-merged options were introduced in 5242860f54 ("tag.c: implement '--merged' and '--no-merged' options", 2015-09-10). It's not apparent from that commit that the documentation is being placed apart from other options, rather than along with them, so this was likely missed in the initial review.
--- Documentation/git-tag.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/git-tag.txt +5 -5
@@ -124,6 +124,11 @@ This option is only applicable when listing tags without annotation lines. Only list tags which contain the specified commit (HEAD if not specified). +--[no-]merged [<commit>]:: + Only list tags whose tips are reachable, or not reachable + if `--no-merged` is used, from the specified commit (`HEAD` + if not specified). + --points-at <object>:: Only list tags of the given object.
@@ -173,11 +178,6 @@ This option is only applicable when listing tags without annotation lines. that of linkgit:git-for-each-ref[1]. When unspecified, defaults to `%(refname:strip=2)`. ---[no-]merged [<commit>]:: - Only list tags whose tips are reachable, or not reachable - if `--no-merged` is used, from the specified commit (`HEAD` - if not specified). - CONFIGURATION ------------- By default, 'git tag' in sign-with-default mode (-s) will use your
Signature · 1 line
2.11.0
PATCH v4 2/16 tag doc: split up the --[no-]merged documentation
In reply to Ævar Arnfjörð BjarmasonSplit up the --[no-]merged documentation into documentation that documents each option independently. This is in line with how "branch" and "for-each-ref" are documented, and makes subsequent changes to discuss the limits & caveats of each option easier to read.
--- Documentation/git-tag.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Documentation/git-tag.txt +7 -4
@@ -124,10 +124,13 @@ This option is only applicable when listing tags without annotation lines. Only list tags which contain the specified commit (HEAD if not specified). ---[no-]merged [<commit>]:: - Only list tags whose tips are reachable, or not reachable - if `--no-merged` is used, from the specified commit (`HEAD` - if not specified). +--merged [<commit>]:: + Only list tags whose tips are reachable from the specified commit + (`HEAD` if not specified). + +--no-merged [<commit>]:: + Only list tags whose tips are not reachable from the specified + commit (`HEAD` if not specified). --points-at <object>:: Only list tags of the given object.
Signature · 1 line
2.11.0
PATCH v4 3/16 tag doc: reword --[no-]merged to talk about commits, not tips
In reply to Ævar Arnfjörð BjarmasonChange the wording for the --merged and --no-merged options to talk about "commits" instead of "tips".
This phrasing was copied from the "branch" documentation in commit 5242860f54 ("tag.c: implement '--merged' and '--no-merged' options", 2015-09-10). Talking about the "tip" is branch nomenclature, not something usually associated with tags.
This phrasing might lead the reader to believe that these options might find tags pointing to trees or blobs, let's instead be explicit and only talk about commits.
--- Documentation/git-tag.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/git-tag.txt +3 -3
@@ -125,11 +125,11 @@ This option is only applicable when listing tags without annotation lines. specified). --merged [<commit>]:: - Only list tags whose tips are reachable from the specified commit - (`HEAD` if not specified). + Only list tags whose commits are reachable from the specified + commit (`HEAD` if not specified). --no-merged [<commit>]:: - Only list tags whose tips are not reachable from the specified + Only list tags whose commits are not reachable from the specified commit (`HEAD` if not specified). --points-at <object>::
Signature · 1 line
2.11.0
PATCH v4 4/16 ref-filter: make combining --merged & --no-merged an error
In reply to Ævar Arnfjörð BjarmasonChange the behavior of specifying --merged & --no-merged to be an error, instead of silently picking the option that was provided last.
Subsequent changes of mine add a --no-contains option in addition to the existing --contains. Providing both of those isn't an error, and has actual meaning.
Making its cousins have different behavior in this regard would be confusing to the user, especially since we'd be silently disregarding some of their command-line input.
--- Documentation/git-branch.txt | 6 ++++-- Documentation/git-for-each-ref.txt | 6 ++++-- Documentation/git-tag.txt | 4 ++-- ref-filter.c | 11 ++++++++++- t/t3200-branch.sh | 4 ++++ t/t6302-for-each-ref-filter.sh | 4 ++++ t/t7004-tag.sh | 4 ++++ 7 files changed, 32 insertions(+), 7 deletions(-)
Documentation/git-branch.txt +4 -2
@@ -215,11 +215,13 @@ start-point is either a local or remote-tracking branch. --merged [<commit>]:: Only list branches whose tips are reachable from the - specified commit (HEAD if not specified). Implies `--list`. + specified commit (HEAD if not specified). Implies `--list`, + incompatible with `--no-merged`. --no-merged [<commit>]:: Only list branches whose tips are not reachable from the - specified commit (HEAD if not specified). Implies `--list`. + specified commit (HEAD if not specified). Implies `--list`, + incompatible with `--merged`. <branchname>:: The name of the branch to create or delete.
Documentation/git-for-each-ref.txt +4 -2
@@ -69,11 +69,13 @@ OPTIONS --merged [<object>]:: Only list refs whose tips are reachable from the - specified commit (HEAD if not specified). + specified commit (HEAD if not specified), + incompatible with `--no-merged`. --no-merged [<object>]:: Only list refs whose tips are not reachable from the - specified commit (HEAD if not specified). + specified commit (HEAD if not specified), + incompatible with `--merged`. --contains [<object>]:: Only list refs which contain the specified commit (HEAD if not
Documentation/git-tag.txt +2 -2
@@ -126,11 +126,11 @@ This option is only applicable when listing tags without annotation lines. --merged [<commit>]:: Only list tags whose commits are reachable from the specified - commit (`HEAD` if not specified). + commit (`HEAD` if not specified), incompatible with `--no-merged`. --no-merged [<commit>]:: Only list tags whose commits are not reachable from the specified - commit (`HEAD` if not specified). + commit (`HEAD` if not specified), incompatible with `--merged`. --points-at <object>:: Only list tags of the given object.
ref-filter.c +10 -1
@@ -2084,8 +2084,17 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) {struct ref_filter *rf = opt->value;unsigned char sha1[20 ]; +int no_merged =starts_with (opt->long_name,"no" ); - rf->merge =starts_with (opt->long_name,"no" ) +if (rf->merge) { +if (no_merged) { +return opterror (opt,"is incompatible with --merged" ,0 ); + }else { +return opterror (opt,"is incompatible with --no-merged" ,0 ); + } + } + + rf->merge = no_merged ?REF_FILTER_MERGED_OMIT :REF_FILTER_MERGED_INCLUDE ;
t/t3200-branch.sh +4 -0
@@ -978,6 +978,10 @@ test_expect_success '--merged catches invalid object names' ' test_must_fail git branch --merged 0000000000000000000000000000000000000000 ' +test_expect_success '--merged is incompatible with --no-merged' ' + test_must_fail git branch --merged HEAD --no-merged HEAD +' + test_expect_success 'tracking with unexpected .fetch refspec' ' rm -rf a b c d && git init a &&
t/t6302-for-each-ref-filter.sh +4 -0
@@ -421,4 +421,8 @@ test_expect_success 'check %(if:notequals=<string>)' ' test_cmp expect actual ' +test_expect_success '--merged is incompatible with --no-merged' ' + test_must_fail git for-each-ref --merged HEAD --no-merged HEAD +' + test_done
t/t7004-tag.sh +4 -0
@@ -1748,6 +1748,10 @@ test_expect_success '--merged cannot be used in non-list mode' ' test_must_fail git tag --merged=mergetest-2 foo ' +test_expect_success '--merged is incompatible with --no-merged' ' + test_must_fail git tag --merged HEAD --no-merged HEAD +' + test_expect_success '--merged shows merged tags' ' cat >expect <<-\EOF && mergetest-1
Signature · 1 line
2.11.0
PATCH v4 5/16 ref-filter: add test for --contains on a non-commit
In reply to Ævar Arnfjörð BjarmasonChange the tag test suite to test for --contains on a tree & blob. It only accepts commits and will spew out "<object> is a tree, not a commit".
It's sufficient to test this just for the "tag" and "branch" commands, because it covers all the machinery shared between "branch" and "for-each-ref".
--- t/t3201-branch-contains.sh | 9 +++++++++ t/t7004-tag.sh | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-)
t/t3201-branch-contains.sh +9 -0
@@ -130,6 +130,15 @@ test_expect_success 'implicit --list conflicts with modification options' ' ' +test_expect_success 'Assert that --contains only works on commits, not trees & blobs' ' + test_must_fail git branch --contains master^{tree} && + blob=$(git hash-object -w --stdin <<-\EOF + Some blob + EOF + ) && + test_must_fail git branch --contains $blob +' + # We want to set up a case where the walk for the tracking info # of one branch crosses the tip of another branch (and make sure # that the latter walk does not mess up our flag to see if it was
t/t7004-tag.sh +3 -1
@@ -1461,7 +1461,9 @@ test_expect_success 'mixing incompatibles modes and options is forbidden' ' test_must_fail git tag -n 100 && test_must_fail git tag -l -m msg && test_must_fail git tag -l -F some file && - test_must_fail git tag -v -s + test_must_fail git tag -v -s && + test_must_fail git tag --contains tag-tree && + test_must_fail git tag --contains tag-blob ' # check points-at
Signature · 1 line
2.11.0
PATCH v4 6/16 tag: remove a TODO item from the test suite
In reply to Ævar Arnfjörð BjarmasonChange the test for "git tag -l" to not have an associated TODO comment saying that it should return non-zero if there's no tags.
This was added in commit ef5a6fb597 ("Add test-script for git-tag", 2007-06-28) when the tests for "tag" were initially added, but at this point changing this would be inconsistent with how "git tag" is a synonym for "git tag -l", and would needlessly break external code that relies on this porcelain command.
--- t/t7004-tag.sh | 2 -- 1 file changed, 2 deletions(-)
t/t7004-tag.sh +0 -2
@@ -16,7 +16,6 @@ tag_exists () { git show-ref --quiet --verify refs/tags/"$1" } -# todo: git tag -l now returns always zero, when fixed, change this test test_expect_success 'listing all tags in an empty tree should succeed' ' git tag -l && git tag
@@ -136,7 +135,6 @@ test_expect_success \ 'listing a tag using a matching pattern should output that tag' \ 'test $(git tag -l mytag) = mytag' -# todo: git tag -l now returns always zero, when fixed, change this test test_expect_success \ 'listing tags using a non-matching pattern should suceed' \ 'git tag -l xxx'
Signature · 1 line
2.11.0
PATCH v4 7/16 tag tests: fix a typo in a test description
In reply to Ævar Arnfjörð BjarmasonChange "suceed" to "succeed" in a test description. The typo has been here since the code was originally added in commit ef5a6fb597 ("Add test-script for git-tag", 2007-06-28).
--- t/t7004-tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t7004-tag.sh +1 -1
@@ -136,7 +136,7 @@ test_expect_success \ 'test $(git tag -l mytag) = mytag' test_expect_success \ - 'listing tags using a non-matching pattern should suceed' \ + 'listing tags using a non-matching pattern should succeed' \ 'git tag -l xxx' test_expect_success \
Signature · 1 line
2.11.0
PATCH v4 8/16 for-each-ref: partly change <object> to <commit> in help
In reply to Ævar Arnfjörð BjarmasonChange mentions of <object> to <commit> in the help output of for-each-ref as appropriate.
Both --[no-]merged and --contains only take commits, but --points-at can take any object, such as a tag pointing to a tree or blob.
--- builtin/for-each-ref.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/for-each-ref.c +2 -2
@@ -8,8 +8,8 @@static char const *const for_each_ref_usage[] = {N_ ("git for-each-ref [<options>] [<pattern>]" ),N_ ("git for-each-ref [--points-at <object>]" ), -N_ ("git for-each-ref [(--merged | --no-merged) [<object>]]" ), -N_ ("git for-each-ref [--contains [<object>]]" ), +N_ ("git for-each-ref [(--merged | --no-merged) [<commit>]]" ), +N_ ("git for-each-ref [--contains [<commit>]]" ),NULL };
Signature · 1 line
2.11.0
PATCH v4 9/16 tag: add more incompatibles mode tests
In reply to Ævar Arnfjörð BjarmasonAmend the test suite to test for more invalid uses like "-l -a" etc.
This change tests the code path in builtin/tag.c between lines:
if (argc == 0 && !cmdmode)
And:
if ((create_tag_object || force) && (cmdmode != 0))
--- t/t7004-tag.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
t/t7004-tag.sh +16 -0
@@ -1455,8 +1455,24 @@ test_expect_success 'checking that initial commit is in all tags' " test_expect_success 'mixing incompatibles modes and options is forbidden' ' test_must_fail git tag -a && + test_must_fail git tag -a -l && + test_must_fail git tag -s && + test_must_fail git tag -s -l && + test_must_fail git tag -m && + test_must_fail git tag -m -l && + test_must_fail git tag -m "hlagh" && + test_must_fail git tag -m "hlagh" -l && + test_must_fail git tag -F && + test_must_fail git tag -F -l && + test_must_fail git tag -f && + test_must_fail git tag -f -l && + test_must_fail git tag -a -s -m -F && + test_must_fail git tag -a -s -m -F -l && test_must_fail git tag -l -v && + test_must_fail git tag -l -d && + test_must_fail git tag -l -v -d && test_must_fail git tag -n 100 && + test_must_fail git tag -n 100 -v && test_must_fail git tag -l -m msg && test_must_fail git tag -l -F some file && test_must_fail git tag -v -s &&
Signature · 1 line
2.11.0
PATCH v4 10/16 parse-options: add OPT_NONEG to the "contains" option
In reply to Ævar Arnfjörð BjarmasonAdd the OPT_NONEG flag to the "contains" option and its hidden synonym "with". Since this was added in commit 694a577519 ("git-branch --contains=commit", 2007-11-07) giving --no-{contains,with} hasn't been an error, but has emitted the help output since filter.with_commit wouldn't get set.
Now git will emit "error: unknown option `no-{contains,with}'" at the top of the help output.
--- parse-options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parse-options.h +2 -2
@@ -258,7 +258,7 @@ extern int parse_opt_passthru_argv(const struct option *, const char *, int); PARSE_OPT_LASTARG_DEFAULT | flag, \ parse_opt_commits, (intptr_t) "HEAD" \ } -#define OPT_CONTAINS (v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, 0) -#define OPT_WITH (v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN) +#define OPT_CONTAINS (v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, PARSE_OPT_NONEG) +#define OPT_WITH (v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)#endif
Signature · 1 line
2.11.0
PATCH v4 11/16 tag: change misleading --list <pattern> documentation
In reply to Ævar Arnfjörð BjarmasonChange the documentation for --list so that it's described as a toggle, not as an option that takes a <pattern> as an argument.
Junio initially documented this in b867c7c23a ("git-tag: -l to list tags (usability).", 2006-02-17), but later Jeff King changed "tag" to accept multiple patterns in 588d0e834b ("tag: accept multiple patterns for --list", 2011-06-20).
However, documenting this as "-l <pattern>" was never correct, as these both worked before Jeff's change:
git tag -l 'v*'
git tag 'v*' -lOne would expect an option that was documented like that to only accept:
git tag --list
git tag --list 'v*rc*'And after Jeff's change, one that took multiple patterns:
git tag --list 'v*rc*' --list '*2.8*'
But since it's actually a toggle all of these work as well, and produce identical output to the last example above:
git tag --list 'v*rc*' '*2.8*'
git tag --list 'v*rc*' '*2.8*' --list --list --list
git tag --list 'v*rc*' '*2.8*' --list -l --list -l --listNow the documentation is more in tune with how the "branch" command describes its --list option since commit cddd127b9a ("branch:
introduce --list option", 2011-08-28).
Change the test suite to assert that these invocations work for the cases that weren't already being tested for.
--- Documentation/git-tag.txt | 15 ++++++++------- t/t7004-tag.sh | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-)
Documentation/git-tag.txt +8 -7
@@ -87,13 +87,14 @@ OPTIONS If no number is given to `-n`, only the first line is printed. 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 - using fnmatch(3)). Multiple patterns may be given; if any of - them matches, the tag is shown. +-l:: +--list:: + List tags. With optional `<pattern>...`, e.g. `git tag --list + 'v-*'`, list only the tags that match the pattern(s). ++ +Running "git tag" without arguments also lists all tags. 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. --sort=<key>:: Sort based on the key given. Prefix `-` to sort in
t/t7004-tag.sh +25 -0
@@ -118,6 +118,18 @@ test_expect_success 'listing all tags if one exists should succeed' ' git tag ' +cat >expect <<EOF +mytag +EOF +test_expect_success 'Multiple -l or --list options are equivalent to one -l option' ' + git tag -l -l >actual && + test_cmp expect actual && + git tag --list --list >actual && + test_cmp expect actual && + git tag --list -l --list >actual && + test_cmp expect actual +' + test_expect_success 'listing all tags if one exists should output that tag' ' test $(git tag -l) = mytag && test $(git tag) = mytag
@@ -336,6 +348,19 @@ test_expect_success 'tag -l can accept multiple patterns' ' test_cmp expect actual ' +# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation +# could leave you with the impression that "-l <pattern> -l <pattern>" +# was how we wanted to accept multiple patterns. +# +# This test should not imply that this is a sane thing to support. but +# since the documentation was worded like it was let's at least find +# out if we're going to break this long-documented form of taking +# multiple patterns. +test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' ' + git tag -l "v1*" -l "v0*" >actual && + test_cmp expect actual +' + test_expect_success 'listing tags in column' ' COLUMNS=40 git tag -l --column=row >actual && cat >expected <<\EOF &&
Signature · 1 line
2.11.0
PATCH v4 12/16 tag: implicitly supply --list given another list-like option
In reply to Ævar Arnfjörð BjarmasonChange the "tag" command to implicitly turn on its --list mode when provided with a list-like option such as --contains, --points-at etc.
This is for consistency with how "branch" works. When "branch" is given a list-like option, such as --contains, it implicitly provides --list. Before this change "tag" would error out on those sorts of invocations. I.e. while both of these worked for "branch":
git branch --contains v2.8.0 <pattern>
git branch --list --contains v2.8.0 <pattern>Only the latter form worked for "tag":
git tag --contains v2.8.0 '*rc*'
git tag --list --contains v2.8.0 '*rc*'Now "tag", like "branch", will implicitly supply --list when a list-like option is provided, and no other conflicting non-list options (such as -d) are present on the command-line.
Spelunking through the history via:
git log --reverse -p -G'only allowed with' -- '*builtin*tag*c'
Reveals that there was no good reason for not allowing this in the first place. The --contains option added in 32c35cfb1e ("git-tag: Add --contains option", 2009-01-26) made this an error. All the other subsequent list-like options that were added copied its pattern of making this usage an error.
The only tests that break as a result of this change are tests that were explicitly checking that this "branch-like" usage wasn't permitted. Change those failing tests to check that this invocation mode is permitted, add extra tests for the list-like options we weren't testing, and tests to ensure that e.g. we don't toggle the list mode in the presence of other conflicting non-list options.
With this change errors messages such as "--contains option is only allowed with -l" don't make sense anymore, since options like --contain turn on -l. Instead we error out when list-like options such as --contain are used in conjunction with conflicting options such as -d or -v.
--- Documentation/git-tag.txt | 17 +++++++++------ builtin/tag.c | 18 ++++++++++------ t/t7004-tag.sh | 55 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 17 deletions(-)
Documentation/git-tag.txt +11 -6
@@ -82,10 +82,11 @@ OPTIONS -n<num>:: <num> specifies how many lines from the annotation, if any, - are printed when using -l. - The default is not to print any annotation lines. - If no number is given to `-n`, only the first line is printed. - If the tag is not annotated, the commit message is displayed instead. + are printed when using -l. Implies `--list`. ++ +The default is not to print any annotation lines. +If no number is given to `-n`, only the first line is printed. +If the tag is not annotated, the commit message is displayed instead. -l:: --list::
@@ -95,6 +96,10 @@ OPTIONS Running "git tag" without arguments also lists all tags. 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. ++ +This option is implicitly supplied if any other list-like option such +as `--contains` is provided. See the documentation for each of those +options for details. --sort=<key>:: Sort based on the key given. Prefix `-` to sort in
@@ -123,7 +128,7 @@ This option is only applicable when listing tags without annotation lines. --contains [<commit>]:: Only list tags which contain the specified commit (HEAD if not - specified). + specified). Implies `--list`. --merged [<commit>]:: Only list tags whose commits are reachable from the specified
@@ -134,7 +139,7 @@ This option is only applicable when listing tags without annotation lines. commit (`HEAD` if not specified), incompatible with `--merged`. --points-at <object>:: - Only list tags of the given object. + Only list tags of the given object. Implies `--list`. -m <msg>:: --message=<msg>::
builtin/tag.c +12 -6
@@ -454,8 +454,14 @@ int cmd_tag(int argc, const char **argv, const char *prefix) } create_tag_object = (opt.sign || annotate || msg.given || msgfile); -if (argc ==0 && !cmdmode) - cmdmode ='l' ; +if (!cmdmode) { +if (argc ==0 ) + cmdmode ='l' ; +else if (filter.with_commit || + filter.points_at.nr || filter.merge_commit || + filter.lines !=-1 ) + cmdmode ='l' ; + }if ((create_tag_object || force) && (cmdmode !=0 ))usage_with_options (git_tag_usage, options);
@@ -485,13 +491,13 @@ int cmd_tag(int argc, const char **argv, const char *prefix)return ret; }if (filter.lines !=-1 ) -die (_ ("-n option is only allowed with -l." )); +die (_ ("-n option is only allowed in list mode" ));if (filter.with_commit) -die (_ ("--contains option is only allowed with -l." )); +die (_ ("--contains option is only allowed in list mode" ));if (filter.points_at.nr) -die (_ ("--points-at option is only allowed with -l." )); +die (_ ("--points-at option is only allowed in list mode" ));if (filter.merge_commit) -die (_ ("--merged and --no-merged option are only allowed with -l" )); +die (_ ("--merged and --no-merged options are only allowed in list mode" ));if (cmdmode =='d' )return for_each_tag_name (argv, delete_tag,NULL );if (cmdmode =='v' ) {
t/t7004-tag.sh +50 -5
99 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 13/16 tag: change --point-at to default to HEAD
In reply to Ævar Arnfjörð BjarmasonChange the --points-at option to default to HEAD for consistency with its siblings --contains, --merged etc. which default to HEAD. Previously we'd get:
$ git tag --points-at 2>&1 | head -n 1
error: option `points-at' requires a valueThis changes behavior added in commit ae7706b9ac (tag: add --points-at list option, 2012-02-08).
--- Documentation/git-tag.txt | 3 ++- builtin/tag.c | 3 ++- t/t7004-tag.sh | 9 ++++++++- 3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/git-tag.txt +2 -1
@@ -139,7 +139,8 @@ This option is only applicable when listing tags without annotation lines. commit (`HEAD` if not specified), incompatible with `--merged`. --points-at <object>:: - Only list tags of the given object. Implies `--list`. + Only list tags of the given object (HEAD if not + specified). Implies `--list`. -m <msg>:: --message=<msg>::
builtin/tag.c +2 -1
@@ -431,7 +431,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix) N_("field name to sort on"), &parse_opt_ref_sorting), {OPTION_CALLBACK ,0 ,"points-at" , &filter.points_at,N_ ("object" ), -N_ ("print only tags of the object" ),0 , parse_opt_object_name +N_ ("print only tags of the object" ),PARSE_OPT_LASTARG_DEFAULT , + parse_opt_object_name, (intptr_t )"HEAD" },OPT_STRING (0 ,"format" , &format,N_ ("format" ),N_ ("format to use for the output" )), OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
t/t7004-tag.sh +8 -1
@@ -1534,7 +1534,8 @@ do " test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" " git tag -n $option HEAD HEAD && - git tag $option HEAD HEAD + git tag $option HEAD HEAD && + git tag $option " done
@@ -1546,6 +1547,12 @@ test_expect_success '--points-at can be used in non-list mode' ' test_cmp expect actual ' +test_expect_success '--points-at is a synonym for --points-at HEAD' ' + echo v4.0 >expect && + git tag --points-at >actual && + test_cmp expect actual +' + test_expect_success '--points-at finds lightweight tags' ' echo v4.0 >expect && git tag --points-at v4.0 >actual &&
Signature · 1 line
2.11.0
PATCH v4 14/16 ref-filter: add --no-contains option to tag/branch/for-each-ref
In reply to Ævar Arnfjörð BjarmasonChange the tag, branch & for-each-ref commands to have a --no-contains option in addition to their longstanding --contains options.
This allows for finding the last-good rollout tag given a known-bad <commit>. Given a hypothetically bad commit cf5c7253e0, the git version to revert to can be found with this hacky two-liner:
(git tag -l 'v[0-9]*'; git tag -l --contains cf5c7253e0 'v[0-9]*') |
sort | uniq -c | grep -E '^ *1 ' | awk '{print $2}' | tail -n 10With this new --no-contains option the same can be achieved with:
git tag -l --no-contains cf5c7253e0 'v[0-9]*' | sort | tail -n 10
As the filtering machinery is shared between the tag, branch & for-each-ref commands, implement this for those commands too. A practical use for this with "branch" is e.g. finding branches which were branched off between v2.8.0 and v2.10.0:
git branch --contains v2.8.0 --no-contains v2.10.0
The "describe" command also has a --contains option, but its semantics are unrelated to what tag/branch/for-each-ref use --contains for. A --no-contains option for "describe" wouldn't make any sense, other than being exactly equivalent to not supplying --contains at all, which would be confusing at best.
Add a --without option to "tag" as an alias for --no-contains, for consistency with --with and --contains. The --with option is undocumented, and possibly the only user of it is
Junio (<[email protected]>). But it's trivial to support, so let's do that.
The additions to the the test suite are inverse copies of the corresponding --contains tests. With this change --no-contains for tag, branch & for-each-ref is just as well tested as the existing --contains option.
In addition to those tests, add a test for "tag" which asserts that --no-contains won't find tree/blob tags, which is slightly unintuitive, but consistent with how --contains works & is documented.
--- Documentation/git-branch.txt | 16 +++- Documentation/git-for-each-ref.txt | 6 +- Documentation/git-tag.txt | 6 +- builtin/branch.c | 5 +- builtin/for-each-ref.c | 3 +- builtin/tag.c | 8 +- contrib/completion/git-completion.bash | 4 +- parse-options.h | 2 + ref-filter.c | 19 +++-- ref-filter.h | 1 + t/t3201-branch-contains.sh | 54 +++++++++++++- t/t6302-for-each-ref-filter.sh | 16 ++++ t/t7004-tag.sh | 130 ++++++++++++++++++++++++++++++++- 13 files changed, 245 insertions(+), 25 deletions(-)
Documentation/git-branch.txt +12 -4
@@ -11,7 +11,8 @@ SYNOPSIS 'git branch' [--color[=<when>] | --no-color] [-r | -a] [--list] [-v [--abbrev=<length> | --no-abbrev]] [--column[=<options>] | --no-column] - [(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>] + [(--merged | --no-merged) [<commit>]] + [--contains [<commit]] [--no-contains [<commit>]] [--sort=<key>] [--points-at <object>] [--format=<format>] [<pattern>...] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>] 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
@@ -35,7 +36,7 @@ as branch creation. With `--contains`, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the -named commit). With `--merged`, only branches merged into the named +named commit), `--no-contains` inverts it. With `--merged`, only branches merged into the named commit (i.e. the branches whose tip commits are reachable from the named commit) will be listed. With `--no-merged` only branches not merged into the named commit will be listed. If the <commit> argument is missing it
@@ -213,6 +214,10 @@ start-point is either a local or remote-tracking branch. Only list branches which contain the specified commit (HEAD if not specified). Implies `--list`. +--no-contains [<commit>]:: + Only list branches which don't contain the specified commit + (HEAD if not specified). Implies `--list`. + --merged [<commit>]:: Only list branches whose tips are reachable from the specified commit (HEAD if not specified). Implies `--list`,
@@ -298,13 +303,16 @@ If you are creating a branch that you want to checkout immediately, it is easier to use the git checkout command with its `-b` option to create a branch and check it out with a single command. -The options `--contains`, `--merged` and `--no-merged` serve three related -but different purposes: +The options `--contains`, `--no-contains`, `--merged` and `--no-merged` +serve four related but different purposes: - `--contains <commit>` is used to find all branches which will need special attention if <commit> were to be rebased or amended, since those branches contain the specified <commit>. +- `--no-contains <commit>` is the inverse of that, i.e. branches that don't + contain the specified <commit>. + - `--merged` is used to find all branches which can be safely deleted, since those branches are fully contained by HEAD.
Documentation/git-for-each-ref.txt +5 -1
@@ -11,7 +11,7 @@ SYNOPSIS 'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl] [(--sort=<key>)...] [--format=<format>] [<pattern>...] [--points-at <object>] [(--merged | --no-merged) [<object>]] - [--contains [<object>]] + [--contains [<object>]] [--no-contains [<object>]] DESCRIPTION -----------
@@ -81,6 +81,10 @@ OPTIONS Only list refs which contain the specified commit (HEAD if not specified). +--no-contains [<object>]:: + Only list refs which don't contain the specified commit (HEAD + if not specified). + --ignore-case:: Sorting and filtering refs are case insensitive.
Documentation/git-tag.txt +5 -1
@@ -12,7 +12,7 @@ SYNOPSIS 'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] <tagname> [<commit> | <object>] 'git tag' -d <tagname>... -'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>] +'git tag' [-n[<num>]] -l [--contains <commit>] [--contains <commit>] [--points-at <object>] [--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>] [--format=<format>] [--[no-]merged [<commit>]] [<pattern>...] 'git tag' -v [--format=<format>] <tagname>...
@@ -130,6 +130,10 @@ This option is only applicable when listing tags without annotation lines. Only list tags which contain the specified commit (HEAD if not specified). Implies `--list`. +--no-contains [<commit>]:: + Only list tags which don't contain the specified commit (HEAD if + not specified). Implies `--list`. + --merged [<commit>]:: Only list tags whose commits are reachable from the specified commit (`HEAD` if not specified), incompatible with `--no-merged`.
builtin/branch.c +4 -1
@@ -562,7 +562,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)OPT_SET_INT ('r' ,"remotes" , &filter.kind,N_ ("act on remote-tracking branches" ),FILTER_REFS_REMOTES ),OPT_CONTAINS (&filter.with_commit,N_ ("print only branches that contain the commit" )), +OPT_NO_CONTAINS (&filter.no_commit,N_ ("print only branches that don't contain the commit" )),OPT_WITH (&filter.with_commit,N_ ("print only branches that contain the commit" )), +OPT_WITHOUT (&filter.no_commit,N_ ("print only branches that don't contain the commit" )),OPT__ABBREV (&filter.abbrev), OPT_GROUP(N_("Specific git-branch actions:")),
@@ -618,7 +620,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc ==0 ) list =1 ; -if (filter.with_commit || filter.merge !=REF_FILTER_MERGED_NONE || filter.points_at.nr) +if (filter.with_commit || filter.merge !=REF_FILTER_MERGED_NONE || filter.points_at.nr || + filter.no_commit) list =1 ; if (!!delete + !!rename + !!new_upstream +
builtin/for-each-ref.c +2 -1
@@ -9,7 +9,7 @@ static char const * const for_each_ref_usage[] = {N_ ("git for-each-ref [<options>] [<pattern>]" ),N_ ("git for-each-ref [--points-at <object>]" ),N_ ("git for-each-ref [(--merged | --no-merged) [<commit>]]" ), -N_ ("git for-each-ref [--contains [<commit>]]" ), +N_ ("git for-each-ref [--contains [<commit>]] [--no-contains [<commit>]]" ), NULL };
@@ -43,6 +43,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)OPT_MERGED (&filter,N_ ("print only refs that are merged" )),OPT_NO_MERGED (&filter,N_ ("print only refs that are not merged" )),OPT_CONTAINS (&filter.with_commit,N_ ("print only refs which contain the commit" )), +OPT_NO_CONTAINS (&filter.no_commit,N_ ("print only refs which don't contain the commit" )),OPT_BOOL (0 ,"ignore-case" , &icase,N_ ("sorting and filtering are case insensitive" )), OPT_END(), };
builtin/tag.c +6 -2
@@ -22,7 +22,7 @@static const char *const git_tag_usage[] = {N_ ("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <tagname> [<head>]" ),N_ ("git tag -d <tagname>..." ), -N_ ("git tag -l [-n[<num>]] [--contains <commit>] [--points-at <object>]" +N_ ("git tag -l [-n[<num>]] [--contains <commit>] [--no-contains <commit>] [--points-at <object>]" "\n\t\t[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]" ),N_ ("git tag -v [--format=<format>] <tagname>..." ),NULL
@@ -424,7 +424,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)OPT_GROUP (N_ ("Tag listing options" )),OPT_COLUMN (0 ,"column" , &colopts,N_ ("show tag list in columns" )),OPT_CONTAINS (&filter.with_commit,N_ ("print only tags that contain the commit" )), +OPT_NO_CONTAINS (&filter.no_commit,N_ ("print only tags that don't contain the commit" )),OPT_WITH (&filter.with_commit,N_ ("print only tags that contain the commit" )), +OPT_WITHOUT (&filter.no_commit,N_ ("print only tags that don't contain the commit" )),OPT_MERGED (&filter,N_ ("print only tags that are merged" )),OPT_NO_MERGED (&filter,N_ ("print only tags that are not merged" )), OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
@@ -458,7 +460,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)if (!cmdmode) {if (argc ==0 ) cmdmode ='l' ; -else if (filter.with_commit || +else if (filter.with_commit || filter.no_commit || filter.points_at.nr || filter.merge_commit || filter.lines !=-1 ) cmdmode ='l' ;
@@ -495,6 +497,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)die (_ ("-n option is only allowed in list mode" ));if (filter.with_commit)die (_ ("--contains option is only allowed in list mode" )); +if (filter.no_commit) +die (_ ("--no-contains option is only allowed in list mode" ));if (filter.points_at.nr)die (_ ("--points-at option is only allowed in list mode" ));if (filter.merge_commit)
contrib/completion/git-completion.bash +2 -2
@@ -1093,7 +1093,7 @@ _git_branch () --*) __gitcomp " --color --no-color --verbose --abbrev= --no-abbrev - --track --no-track --contains --merged --no-merged + --track --no-track --contains --no-contains --merged --no-merged --set-upstream-to= --edit-description --list --unset-upstream --delete --move --remotes --column --no-column --sort= --points-at
@@ -2862,7 +2862,7 @@ _git_tag () __gitcomp " --list --delete --verify --annotate --message --file --sign --cleanup --local-user --force --column --sort= - --contains --points-at --merged --no-merged --create-reflog + --contains --no-contains --points-at --merged --no-merged --create-reflog " ;; esac
parse-options.h +2 -0
@@ -259,6 +259,8 @@ extern int parse_opt_passthru_argv(const struct option *, const char *, int); parse_opt_commits, (intptr_t) "HEAD" \ }#define OPT_CONTAINS (v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, PARSE_OPT_NONEG) +#define OPT_NO_CONTAINS (v, h) _OPT_CONTAINS_OR_WITH("no-contains", v, h, PARSE_OPT_NONEG)#define OPT_WITH (v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG) +#define OPT_WITHOUT (v, h) _OPT_CONTAINS_OR_WITH("without", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)#endif
ref-filter.c +13 -6
@@ -1487,6 +1487,7 @@ struct ref_filter_cbdata {struct ref_array *array;struct ref_filter *filter;struct contains_cache contains_cache; +struct contains_cache no_contains_cache; };/*
@@ -1586,11 +1587,11 @@ static enum contains_result contains_tag_algo(struct commit *candidate, }static int commit_contains (struct ref_filter *filter,struct commit *commit, -struct contains_cache *cache) +struct commit_list *list,struct contains_cache *cache) {if (filter->with_commit_tag_algo) -return contains_tag_algo (commit, filter->with_commit, cache) ==CONTAINS_YES ; -return is_descendant_of (commit, filter->with_commit); +return contains_tag_algo (commit, list, cache) ==CONTAINS_YES ; +return is_descendant_of (commit, list); }/*
@@ -1780,13 +1781,17 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,* obtain the commit using the 'oid' available and discard all * non-commits early. The actual filtering is done later. */ -if (filter->merge_commit || filter->with_commit || filter->verbose) { +if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) { commit =lookup_commit_reference_gently (oid->hash,1 );if (!commit)return 0 ; -/* We perform the filtering for the '--contains' option */ +/* We perform the filtering for the '--contains' option... */ if (filter->with_commit && - !commit_contains (filter, commit, &ref_cbdata->contains_cache)) + !commit_contains (filter, commit, filter->with_commit, &ref_cbdata->contains_cache)) +return 0 ; +/* ...or for the `--no-contains' option */ +if (filter->no_commit && +commit_contains (filter, commit, filter->no_commit, &ref_cbdata->no_contains_cache))return 0 ; }
@@ -1887,6 +1892,7 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int filter->kind = type &FILTER_REFS_KIND_MASK ;init_contains_cache (&ref_cbdata.contains_cache); +init_contains_cache (&ref_cbdata.no_contains_cache);/* Simple per-ref filtering */ if (!filter->kind)
@@ -1911,6 +1917,7 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int }clear_contains_cache (&ref_cbdata.contains_cache); +clear_contains_cache (&ref_cbdata.no_contains_cache);/* Filters that need revision walking */ if (filter->merge_commit)
ref-filter.h +1 -0
@@ -53,6 +53,7 @@ struct ref_filter {const char **name_patterns;struct sha1_array points_at;struct commit_list *with_commit; +struct commit_list *no_commit;enum {REF_FILTER_MERGED_NONE =0 ,
t/t3201-branch-contains.sh +51 -3
93 lines not on this page · raw message
t/t6302-for-each-ref-filter.sh +16 -0
@@ -93,6 +93,22 @@ test_expect_success 'filtering with --contains' ' test_cmp expect actual ' +test_expect_success 'filtering with --no-contains' ' + cat >expect <<-\EOF && + refs/tags/one + EOF + git for-each-ref --format="%(refname)" --no-contains=two >actual && + test_cmp expect actual +' + +test_expect_success 'filtering with --contains and --no-contains' ' + cat >expect <<-\EOF && + refs/tags/two + EOF + git for-each-ref --format="%(refname)" --contains=two --no-contains=three >actual && + test_cmp expect actual +' + test_expect_success '%(color) must fail' ' test_must_fail git for-each-ref --format="%(color)%(refname)" '
t/t7004-tag.sh +126 -4
190 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v4 15/16 ref-filter: reflow recently changed branch/tag/for-each-ref docs
In reply to Ævar Arnfjörð BjarmasonReflow the recently changed branch/tag-for-each-ref documentation. This change shows no changes under --word-diff, except the innocuous change of moving git-tag.txt's "[--sort=<key>]" around slightly.
--- Documentation/git-branch.txt | 15 ++++++++------- Documentation/git-tag.txt | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-)
Documentation/git-branch.txt +8 -7
@@ -10,9 +10,9 @@ SYNOPSIS [verse] 'git branch' [--color[=<when>] | --no-color] [-r | -a] [--list] [-v [--abbrev=<length> | --no-abbrev]] - [--column[=<options>] | --no-column] + [--column[=<options>] | --no-column] [--sort=<key>] [(--merged | --no-merged) [<commit>]] - [--contains [<commit]] [--no-contains [<commit>]] [--sort=<key>] + [--contains [<commit]] [--no-contains [<commit>]] [--points-at <object>] [--format=<format>] [<pattern>...] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>] 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
@@ -36,11 +36,12 @@ as branch creation. With `--contains`, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the -named commit), `--no-contains` inverts it. With `--merged`, only branches merged into the named -commit (i.e. the branches whose tip commits are reachable from the named -commit) will be listed. With `--no-merged` only branches not merged into -the named commit will be listed. If the <commit> argument is missing it -defaults to `HEAD` (i.e. the tip of the current branch). +named commit), `--no-contains` inverts it. With `--merged`, only branches +merged into the named commit (i.e. the branches whose tip commits are +reachable from the named commit) will be listed. With `--no-merged` only +branches not merged into the named commit will be listed. If the <commit> +argument is missing it defaults to `HEAD` (i.e. the tip of the current +branch). The command's second form creates a new branch head named <branchname> which points to the current `HEAD`, or <start-point> if given.
Documentation/git-tag.txt +4 -3
@@ -12,9 +12,10 @@ SYNOPSIS 'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] <tagname> [<commit> | <object>] 'git tag' -d <tagname>... -'git tag' [-n[<num>]] -l [--contains <commit>] [--contains <commit>] [--points-at <object>] - [--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>] - [--format=<format>] [--[no-]merged [<commit>]] [<pattern>...] +'git tag' [-n[<num>]] -l [--contains <commit>] [--contains <commit>] + [--points-at <object>] [--column[=<options>] | --no-column] + [--create-reflog] [--sort=<key>] [--format=<format>] + [--[no-]merged [<commit>]] [<pattern>...] 'git tag' -v [--format=<format>] <tagname>... DESCRIPTION
Signature · 1 line
2.11.0
PATCH v4 16/16 tag: add tests for --with and --without
In reply to Ævar Arnfjörð BjarmasonChange the test suite to test for these synonyms for --contains and --no-contains, respectively.
Before this change there were no tests for them at all. This doesn't exhaustively test for them as well as their --contains and --no-contains synonyms, but at least it's something.
--- t/t7004-tag.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/t7004-tag.sh +4 -2
@@ -1599,10 +1599,12 @@ test_expect_success 'mixing incompatibles modes and options is forbidden' ' test_must_fail git tag --contains tag-blob && test_must_fail git tag --no-contains tag-tree && test_must_fail git tag --no-contains tag-blob && - test_must_fail git tag --contains --no-contains + test_must_fail git tag --contains --no-contains && + test_must_fail git tag --no-with HEAD && + test_must_fail git tag --no-without HEAD ' -for option in --contains --no-contains --merged --no-merged --points-at +for option in --contains --with --no-contains --without --merged --no-merged --points-at do test_expect_success "mixing incompatible modes with $option is forbidden" " test_must_fail git tag -d $option HEAD &&
Signature · 1 line
2.11.0