branch: add '--points-at' option

Add the '--points-at' option provided by 'ref-filter'. The option lets the user to list only branches which points at the given object. 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 Sep 23, 2015 at 23:41 UTC aa3bc55e408d4daab52239d6b80f7d4bb87f6de7
3 files changed +20 -2
Documentation/git-branch.txt
+5 -1
@@ -11,7 +11,8 @@ SYNOPSIS
11 'git branch' [--color[=<when>] | --no-color] [-r | -a]
12 [--list] [-v [--abbrev=<length> | --no-abbrev]]
13 [--column[=<options>] | --no-column]
14 - [(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>] [<pattern>...]
14 + [(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>]
15 + [--points-at <object>] [<pattern>...]
16 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
17 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
18 'git branch' --unset-upstream [<branchname>]
@@ -240,6 +241,9 @@ start-point is either a local or remote-tracking branch.
241 finally remote-tracking branches.
242
243
244 +--points-at <object>::
245 + Only list branches of the given object.
246 +
247 Examples
248 --------
249
builtin/branch.c
+6 -1
@@ -26,6 +26,7 @@ static const char * const builtin_branch_usage[] = {
26 N_("git branch [<options>] [-l] [-f] <branch-name> [<start-point>]"),
27 N_("git branch [<options>] [-r] (-d | -D) <branch-name>..."),
28 N_("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>"),
29 + N_("git branch [<options>] [-r | -a] [--points-at]"),
30 NULL
31 };
32
@@ -646,6 +647,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
647 OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")),
648 OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
649 N_("field name to sort on"), &parse_opt_ref_sorting),
650 + {
651 + OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
652 + N_("print only branches of the object"), 0, parse_opt_object_name
653 + },
654 OPT_END(),
655 };
656
@@ -674,7 +679,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
679 if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0)
680 list = 1;
681
677 - if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE)
682 + if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE || filter.points_at.nr)
683 list = 1;
684
685 if (!!delete + !!rename + !!new_upstream +
t/t3203-branch-output.sh
+9
@@ -154,4 +154,13 @@ test_expect_success 'git branch `--sort` option' '
154 test_i18ncmp expect actual
155 '
156
157 +test_expect_success 'git branch --points-at option' '
158 + cat >expect <<-\EOF &&
159 + branch-one
160 + master
161 + EOF
162 + git branch --points-at=branch-one >actual &&
163 + test_cmp expect actual
164 +'
165 +
166 test_done