Skip to content

Commit aa3bc55

Browse files
KarthikNayakgitster
authored andcommitted
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 <[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 aedcb7d commit aa3bc55

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Documentation/git-branch.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ SYNOPSIS
1111
'git branch' [--color[=<when>] | --no-color] [-r | -a]
1212
[--list] [-v [--abbrev=<length> | --no-abbrev]]
1313
[--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>...]
1516
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
1617
'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
1718
'git branch' --unset-upstream [<branchname>]
@@ -240,6 +241,9 @@ start-point is either a local or remote-tracking branch.
240241
finally remote-tracking branches.
241242

242243

244+
--points-at <object>::
245+
Only list branches of the given object.
246+
243247
Examples
244248
--------
245249

builtin/branch.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static const char * const builtin_branch_usage[] = {
2626
N_("git branch [<options>] [-l] [-f] <branch-name> [<start-point>]"),
2727
N_("git branch [<options>] [-r] (-d | -D) <branch-name>..."),
2828
N_("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>"),
29+
N_("git branch [<options>] [-r | -a] [--points-at]"),
2930
NULL
3031
};
3132

@@ -646,6 +647,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
646647
OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")),
647648
OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
648649
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+
},
649654
OPT_END(),
650655
};
651656

@@ -674,7 +679,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
674679
if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0)
675680
list = 1;
676681

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)
678683
list = 1;
679684

680685
if (!!delete + !!rename + !!new_upstream +

t/t3203-branch-output.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,13 @@ test_expect_success 'git branch `--sort` option' '
154154
test_i18ncmp expect actual
155155
'
156156

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+
157166
test_done

0 commit comments

Comments
 (0)