From 17d6c744dc0d5ed4cd0f228da14239ea2654f05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 21 Mar 2017 12:58:49 +0000 Subject: ref-filter: make combining --merged & --no-merged an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change 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. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 092f1bc..e465298 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -215,11 +215,13 @@ start-point is either a local or remote-tracking branch. --merged []:: 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 []:: 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`. :: The name of the branch to create or delete. diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 111e1be..4d55893 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -69,11 +69,13 @@ OPTIONS --merged []:: 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 []:: 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 []:: Only list refs which contain the specified commit (HEAD if not diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt index 3abf912..448fdf3 100644 --- a/Documentation/git-tag.txt +++ b/Documentation/git-tag.txt @@ -126,11 +126,11 @@ This option is only applicable when listing tags without annotation lines. --merged []:: 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 []:: 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 :: Only list tags of the given object. diff --git a/ref-filter.c b/ref-filter.c index 7eeecc6..81da37b 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -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; diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index e36ed3b..f286f39 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -953,6 +953,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 && diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh index a09a1a4..d36d5dc 100755 --- a/t/t6302-for-each-ref-filter.sh +++ b/t/t6302-for-each-ref-filter.sh @@ -421,4 +421,8 @@ test_expect_success 'check %(if:notequals=)' ' 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 diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index b4698ab..4579066 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -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 -- cgit v0.10.2-6-g49f6