git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 8/8] branch: add '--points-at' option

From
Karthik Nayak <karthik.188@gmail.com>
Date
Sep 23, 2015, 18:11 UTC
Message-ID
<1443031873-25280-9-git-send-email-Karthik.188@gmail.com>
In-Reply-To
<1443031873-25280-1-git-send-email-Karthik.188@gmail.com>

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>
---
 Documentation/git-branch.txt | 6 +++++-
 builtin/branch.c             | 7 ++++++-
 t/t3203-branch-output.sh     | 9 +++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index c45295d..03c7af1 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -11,7 +11,8 @@ SYNOPSIS
 'git branch' [--color[=<when>] | --no-color] [-r | -a]
 	[--list] [-v [--abbrev=<length> | --no-abbrev]]
 	[--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-to=<upstream> | -u <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.
 
 
+--points-at <object>::
+	Only list branches of the given object.
+
 Examples
 --------
 
diff --git a/builtin/branch.c b/builtin/branch.c
index b83116a..b7a60f4 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -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>] [-r] (-d | -D) <branch-name>..."),
 	N_("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>"),
+	N_("git branch [<options>] [-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 a427163..f1ae5ff 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
-- 
2.5.1
Previous: Karthik NayakNext: Matthieu Moy
Message 19 of 27 in “port branch.c to use the filtering part of ref-filter.”
  1. 0/8 port branch.c to use the filtering part of ref-filter.Karthik Nayak, Sep 23, 2015
  2. 1/8 branch: refactor width computationKarthik Nayak, Sep 23, 2015
  3. 2/8 branch: bump get_head_description() to the topKarthik Nayak, Sep 23, 2015
  4. 3/8 branch: roll show_detached HEAD into regular ref_listKarthik Nayak, Sep 23, 2015
  5. 4/8 branch: move 'current' check down to the presentation layerKarthik Nayak, Sep 23, 2015
  6. 5/8 branch: drop non-commit error reportingKarthik Nayak, Sep 23, 2015
  7. Matthieu MoySep 23, 2015
  8. Karthik NayakSep 24, 2015
  9. Junio C HamanoSep 23, 2015
  10. Matthieu MoySep 23, 2015
  11. Junio C HamanoSep 23, 2015
  12. Junio C HamanoSep 23, 2015
  13. Junio C HamanoSep 23, 2015
  14. Matthieu MoySep 24, 2015
  15. Junio C HamanoSep 23, 2015
  16. Karthik NayakSep 24, 2015
  17. 6/8 branch.c: use 'ref-filter' data structuresKarthik Nayak, Sep 23, 2015
  18. 7/8 branch.c: use 'ref-filter' APIsKarthik Nayak, Sep 23, 2015
  19. 8/8 branch: add '--points-at' optionKarthik Nayak, Sep 23, 2015
  20. Matthieu MoySep 23, 2015
  21. Junio C HamanoSep 23, 2015
  22. Karthik NayakSep 24, 2015
  23. 5/8 branch: drop non-commit error reportingKarthik Nayak, Sep 24, 2015
  24. Matthieu MoySep 25, 2015
  25. Junio C HamanoSep 25, 2015
  26. Matthieu MoySep 25, 2015
  27. Karthik NayakSep 25, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.