Skip to content

Commit 17d6c74

Browse files
avargitster
authored andcommitted
ref-filter: make combining --merged & --no-merged an error
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8881d35 commit 17d6c74

File tree

7 files changed

+32
-7
lines changed

7 files changed

+32
-7
lines changed

Documentation/git-branch.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,13 @@ start-point is either a local or remote-tracking branch.
215215

216216
--merged [<commit>]::
217217
Only list branches whose tips are reachable from the
218-
specified commit (HEAD if not specified). Implies `--list`.
218+
specified commit (HEAD if not specified). Implies `--list`,
219+
incompatible with `--no-merged`.
219220

220221
--no-merged [<commit>]::
221222
Only list branches whose tips are not reachable from the
222-
specified commit (HEAD if not specified). Implies `--list`.
223+
specified commit (HEAD if not specified). Implies `--list`,
224+
incompatible with `--merged`.
223225

224226
<branchname>::
225227
The name of the branch to create or delete.

Documentation/git-for-each-ref.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ OPTIONS
6969

7070
--merged [<object>]::
7171
Only list refs whose tips are reachable from the
72-
specified commit (HEAD if not specified).
72+
specified commit (HEAD if not specified),
73+
incompatible with `--no-merged`.
7374

7475
--no-merged [<object>]::
7576
Only list refs whose tips are not reachable from the
76-
specified commit (HEAD if not specified).
77+
specified commit (HEAD if not specified),
78+
incompatible with `--merged`.
7779

7880
--contains [<object>]::
7981
Only list refs which contain the specified commit (HEAD if not

Documentation/git-tag.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ This option is only applicable when listing tags without annotation lines.
126126

127127
--merged [<commit>]::
128128
Only list tags whose commits are reachable from the specified
129-
commit (`HEAD` if not specified).
129+
commit (`HEAD` if not specified), incompatible with `--no-merged`.
130130

131131
--no-merged [<commit>]::
132132
Only list tags whose commits are not reachable from the specified
133-
commit (`HEAD` if not specified).
133+
commit (`HEAD` if not specified), incompatible with `--merged`.
134134

135135
--points-at <object>::
136136
Only list tags of the given object.

ref-filter.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,17 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
20842084
{
20852085
struct ref_filter *rf = opt->value;
20862086
unsigned char sha1[20];
2087+
int no_merged = starts_with(opt->long_name, "no");
20872088

2088-
rf->merge = starts_with(opt->long_name, "no")
2089+
if (rf->merge) {
2090+
if (no_merged) {
2091+
return opterror(opt, "is incompatible with --merged", 0);
2092+
} else {
2093+
return opterror(opt, "is incompatible with --no-merged", 0);
2094+
}
2095+
}
2096+
2097+
rf->merge = no_merged
20892098
? REF_FILTER_MERGED_OMIT
20902099
: REF_FILTER_MERGED_INCLUDE;
20912100

t/t3200-branch.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ test_expect_success '--merged catches invalid object names' '
953953
test_must_fail git branch --merged 0000000000000000000000000000000000000000
954954
'
955955

956+
test_expect_success '--merged is incompatible with --no-merged' '
957+
test_must_fail git branch --merged HEAD --no-merged HEAD
958+
'
959+
956960
test_expect_success 'tracking with unexpected .fetch refspec' '
957961
rm -rf a b c d &&
958962
git init a &&

t/t6302-for-each-ref-filter.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,8 @@ test_expect_success 'check %(if:notequals=<string>)' '
421421
test_cmp expect actual
422422
'
423423

424+
test_expect_success '--merged is incompatible with --no-merged' '
425+
test_must_fail git for-each-ref --merged HEAD --no-merged HEAD
426+
'
427+
424428
test_done

t/t7004-tag.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,10 @@ test_expect_success '--merged cannot be used in non-list mode' '
17481748
test_must_fail git tag --merged=mergetest-2 foo
17491749
'
17501750

1751+
test_expect_success '--merged is incompatible with --no-merged' '
1752+
test_must_fail git tag --merged HEAD --no-merged HEAD
1753+
'
1754+
17511755
test_expect_success '--merged shows merged tags' '
17521756
cat >expect <<-\EOF &&
17531757
mergetest-1

0 commit comments

Comments
 (0)