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>
This commit is contained in:
Karthik Nayak 2015-09-23 23:41:13 +05:30 committed by Junio C Hamano
parent aedcb7dc75
commit aa3bc55e40
3 changed files with 20 additions and 2 deletions

View file

@ -11,7 +11,8 @@ SYNOPSIS
'git branch' [--color[=<when>] | --no-color] [-r | -a] 'git branch' [--color[=<when>] | --no-color] [-r | -a]
[--list] [-v [--abbrev=<length> | --no-abbrev]] [--list] [-v [--abbrev=<length> | --no-abbrev]]
[--column[=<options>] | --no-column] [--column[=<options>] | --no-column]
[(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>] [<pattern>...] [(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>]
[--points-at <object>] [<pattern>...]
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>] 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
'git branch' --unset-upstream [<branchname>] 'git branch' --unset-upstream [<branchname>]
@ -240,6 +241,9 @@ start-point is either a local or remote-tracking branch.
finally remote-tracking branches. finally remote-tracking branches.
--points-at <object>::
Only list branches of the given object.
Examples Examples
-------- --------

View file

@ -26,6 +26,7 @@ static const char * const builtin_branch_usage[] = {
N_("git branch [<options>] [-l] [-f] <branch-name> [<start-point>]"), N_("git branch [<options>] [-l] [-f] <branch-name> [<start-point>]"),
N_("git branch [<options>] [-r] (-d | -D) <branch-name>..."), N_("git branch [<options>] [-r] (-d | -D) <branch-name>..."),
N_("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>"), N_("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>"),
N_("git branch [<options>] [-r | -a] [--points-at]"),
NULL NULL
}; };
@ -646,6 +647,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")), OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")),
OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"), OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
N_("field name to sort on"), &parse_opt_ref_sorting), N_("field name to sort on"), &parse_opt_ref_sorting),
{
OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
N_("print only branches of the object"), 0, parse_opt_object_name
},
OPT_END(), OPT_END(),
}; };
@ -674,7 +679,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0) if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0)
list = 1; list = 1;
if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE) if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE || filter.points_at.nr)
list = 1; list = 1;
if (!!delete + !!rename + !!new_upstream + if (!!delete + !!rename + !!new_upstream +

View file

@ -154,4 +154,13 @@ test_expect_success 'git branch `--sort` option' '
test_i18ncmp expect actual test_i18ncmp expect actual
' '
test_expect_success 'git branch --points-at option' '
cat >expect <<-\EOF &&
branch-one
master
EOF
git branch --points-at=branch-one >actual &&
test_cmp expect actual
'
test_done test_done