for-each-ref: add '--merged' and '--no-merged' options
Add the '--merged' and '--no-merged' options provided by 'ref-filter'. The '--merged' option lets the user to only list refs merged into the named commit. The '--no-merged' option lets the user to only list refs not merged into the named commit. Add documentation and tests for the same. Based-on-patch-by: Jeff King <peff@peff.net> 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
7c32834813bd6aee5ce5b2c4131d9f34249bc9e3
3 files changed
+35
-1
Documentation/git-for-each-ref.txt
+9
-1
@@ -10,7 +10,7 @@ SYNOPSIS
10
[verse]
11
'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
12
[(--sort=<key>)...] [--format=<format>] [<pattern>...]
13
- [--points-at <object>]
13
+ [--points-at <object>] [(--merged | --no-merged) [<object>]]
14
15
DESCRIPTION
16
-----------
@@ -66,6 +66,14 @@ OPTIONS
66
--points-at <object>::
67
Only list refs which points at the given object.
68
69
+--merged [<object>]::
70
+ Only list refs whose tips are reachable from the
71
+ specified commit (HEAD if not specified).
72
+
73
+--no-merged [<object>]::
74
+ Only list refs whose tips are not reachable from the
75
+ specified commit (HEAD if not specified).
76
+
77
FIELD NAMES
78
-----------
79
builtin/for-each-ref.c
+3
@@ -8,6 +8,7 @@
8
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
NULL
13
};
14
@@ -38,6 +39,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
39
OPT_CALLBACK(0, "points-at", &filter.points_at,
40
N_("object"), N_("print only refs which points at the given object"),
41
parse_opt_object_name),
42
+ OPT_MERGED(&filter, N_("print only refs that are merged")),
43
+ OPT_NO_MERGED(&filter, N_("print only refs that are not merged")),
44
OPT_END(),
45
};
46
t/t6302-for-each-ref-filter.sh
+23
@@ -43,4 +43,27 @@ test_expect_success 'check signed tags with --points-at' '
43
test_cmp expect actual
44
'
45
46
+test_expect_success 'filtering with --merged' '
47
+ cat >expect <<-\EOF &&
48
+ refs/heads/master
49
+ refs/odd/spot
50
+ refs/tags/one
51
+ refs/tags/three
52
+ refs/tags/two
53
+ EOF
54
+ git for-each-ref --format="%(refname)" --merged=master >actual &&
55
+ test_cmp expect actual
56
+'
57
+
58
+test_expect_success 'filtering with --no-merged' '
59
+ cat >expect <<-\EOF &&
60
+ refs/heads/side
61
+ refs/tags/double-tag
62
+ refs/tags/four
63
+ refs/tags/signed-tag
64
+ EOF
65
+ git for-each-ref --format="%(refname)" --no-merged=master >actual &&
66
+ test_cmp expect actual
67
+'
68
+
69
test_done