Skip to content

Commit 4a71109

Browse files
KarthikNayakgitster
authored andcommitted
for-each-ref: add '--contains' option
Add the '--contains' option provided by 'ref-filter'. The '--contains' option lists only refs which contain the mentioned commit (HEAD if no commit is explicitly given). Add documentation and tests for the same. Mentored-by: Christian Couder <[email protected]> Mentored-by: Matthieu Moy <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee2bd06 commit 4a71109

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Documentation/git-for-each-ref.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SYNOPSIS
1111
'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
1212
[(--sort=<key>)...] [--format=<format>] [<pattern>...]
1313
[--points-at <object>] [(--merged | --no-merged) [<object>]]
14+
[--contains [<object>]]
1415

1516
DESCRIPTION
1617
-----------
@@ -74,6 +75,10 @@ OPTIONS
7475
Only list refs whose tips are not reachable from the
7576
specified commit (HEAD if not specified).
7677

78+
--contains [<object>]::
79+
Only list tags which contain the specified commit (HEAD if not
80+
specified).
81+
7782
FIELD NAMES
7883
-----------
7984

builtin/for-each-ref.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ static char const * const for_each_ref_usage[] = {
99
N_("git for-each-ref [<options>] [<pattern>]"),
1010
N_("git for-each-ref [--points-at <object>]"),
1111
N_("git for-each-ref [(--merged | --no-merged) [<object>]]"),
12+
N_("git for-each-ref [--contains [<object>]]"),
1213
NULL
1314
};
1415

@@ -41,6 +42,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
4142
parse_opt_object_name),
4243
OPT_MERGED(&filter, N_("print only refs that are merged")),
4344
OPT_NO_MERGED(&filter, N_("print only refs that are not merged")),
45+
OPT_CONTAINS(&filter.with_commit, N_("print only refs which contain the commit")),
4446
OPT_END(),
4547
};
4648

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,19 @@ test_expect_success 'filtering with --no-merged' '
6666
test_cmp expect actual
6767
'
6868

69+
test_expect_success 'filtering with --contains' '
70+
cat >expect <<-\EOF &&
71+
refs/heads/master
72+
refs/heads/side
73+
refs/odd/spot
74+
refs/tags/double-tag
75+
refs/tags/four
76+
refs/tags/signed-tag
77+
refs/tags/three
78+
refs/tags/two
79+
EOF
80+
git for-each-ref --format="%(refname)" --contains=two >actual &&
81+
test_cmp expect actual
82+
'
83+
6984
test_done

0 commit comments

Comments
 (0)