From: Karthik Nayak Date: Wed, 23 Sep 2015 18:11:13 +0000 (+0530) Subject: branch: add '--points-at' option X-Git-Tag: v2.7.0-rc0~109^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/aa3bc55e408d4daab52239d6b80f7d4bb87f6de7?hp=--cc 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 Mentored-by: Matthieu Moy Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- aa3bc55e408d4daab52239d6b80f7d4bb87f6de7 diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index c45295d988..03c7af1b90 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -11,7 +11,8 @@ SYNOPSIS 'git branch' [--color[=] | --no-color] [-r | -a] [--list] [-v [--abbrev= | --no-abbrev]] [--column[=] | --no-column] - [(--merged | --no-merged | --contains) []] [--sort=] [...] + [(--merged | --no-merged | --contains) []] [--sort=] + [--points-at ] [...] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] [] 'git branch' (--set-upstream-to= | -u ) [] 'git branch' --unset-upstream [] @@ -240,6 +241,9 @@ start-point is either a local or remote-tracking branch. finally remote-tracking branches. +--points-at :: + Only list branches of the given object. + Examples -------- diff --git a/builtin/branch.c b/builtin/branch.c index b83116a609..b7a60f41e7 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -26,6 +26,7 @@ static const char * const builtin_branch_usage[] = { N_("git branch [] [-l] [-f] []"), N_("git branch [] [-r] (-d | -D) ..."), N_("git branch [] (-m | -M) [] "), + N_("git branch [] [-r | -a] [--points-at]"), 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_CALLBACK(0 , "sort", sorting_tail, N_("key"), 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(), }; @@ -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) 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; if (!!delete + !!rename + !!new_upstream + diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index a427163c4d..f1ae5ff662 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -154,4 +154,13 @@ test_expect_success 'git branch `--sort` option' ' 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