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 <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Jul 7, 2015 at 21:36 UTC 4a71109aa442ba1a7045d36f6b148113c95ffc48
3 files changed +22
Documentation/git-for-each-ref.txt
+5
@@ -11,6 +11,7 @@ SYNOPSIS
11 'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
12 [(--sort=<key>)...] [--format=<format>] [<pattern>...]
13 [--points-at <object>] [(--merged | --no-merged) [<object>]]
14 + [--contains [<object>]]
15
16 DESCRIPTION
17 -----------
@@ -74,6 +75,10 @@ OPTIONS
75 Only list refs whose tips are not reachable from the
76 specified commit (HEAD if not specified).
77
78 +--contains [<object>]::
79 + Only list tags which contain the specified commit (HEAD if not
80 + specified).
81 +
82 FIELD NAMES
83 -----------
84
builtin/for-each-ref.c
+2
@@ -9,6 +9,7 @@ static char const * const for_each_ref_usage[] = {
9 N_("git for-each-ref [<options>] [<pattern>]"),
10 N_("git for-each-ref [--points-at <object>]"),
11 N_("git for-each-ref [(--merged | --no-merged) [<object>]]"),
12 + N_("git for-each-ref [--contains [<object>]]"),
13 NULL
14 };
15
@@ -41,6 +42,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
42 parse_opt_object_name),
43 OPT_MERGED(&filter, N_("print only refs that are merged")),
44 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")),
46 OPT_END(),
47 };
48
t/t6302-for-each-ref-filter.sh
+15
@@ -66,4 +66,19 @@ test_expect_success 'filtering with --no-merged' '
66 test_cmp expect actual
67 '
68
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 +
84 test_done