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

[PATCH] Document and test the new % shotcut for the tracked branch

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Mar 20, 2009, 10:04 UTC
Message-ID
<1237543471-27248-1-git-send-email-git@drmicha.warpmail.net>
In-Reply-To
<alpine.DEB.1.00.0903201027450.10279@pacific.mpi-cbg.de>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Johannes Schindelin venit, vidit, dixit 20.03.2009 10:29:
Show 14 quoted lines
> 
> Often, it is quite interesting to inspect the branch tracked by a given
> branch.  This patch introduces a nice notation to get at the tracked
> branch: 'BEL<branch>' can be used to access that tracked branch.
> 
> A special shortcut 'BEL' refers to the branch tracked by the current branch.
> 
> Suggested by Pasky and Shawn.
> 
> This patch extends the function introduced to handle the nth-last branch
> (via the {-<n>} notation); therefore that function name was renamed to
> something more general.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
I guess you beat me to it then, which is fine.

But haven't you seen my note about the failing test either? The code below tests with branches which track local branches. merge and remote is set for the branch in question ("tracking"), it's just that remote is ".". It seems that the remote.c code does not set up merge info for these branches.

<Goes to figure out how to enter BEL...>
 Documentation/git-rev-parse.txt |    3 ++
 t/t1506-rev-parse-track.sh      |   60 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100755 t/t1506-rev-parse-track.sh
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 5ed2bc8..dafcfe8 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -215,6 +215,9 @@ when you run 'git-merge'.
 * The special construct '@\{-<n>\}' means the <n>th branch checked out
   before the current one.
 
+* A prefix '%', optionally followed by a branchname '<branch>', means the
+  branch tracked by '<branch>'. '<branch>' defaults to the current branch.
+
 * A suffix '{caret}' to a revision parameter means the first parent of
   that commit object.  '{caret}<n>' means the <n>th parent (i.e.
   'rev{caret}'
diff --git a/t/t1506-rev-parse-track.sh b/t/t1506-rev-parse-track.sh
new file mode 100755
index 0000000..1ca1dd6
--- /dev/null
+++ b/t/t1506-rev-parse-track.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+test_description='test % syntax'
+
+. ./test-lib.sh
+
+
+make_commit () {
+	echo "$1" > "$1" &&
+	git add "$1" &&
+	git commit -m "$1"
+}
+
+
+test_expect_success 'setup' '
+
+	make_commit 1 &&
+	git branch tracked &&
+	make_commit 2 &&
+	git checkout tracked &&
+	make_commit 3 &&
+	git checkout --track -b tracking tracked
+	make_commit 4 &&
+	git checkout master
+
+'
+
+# tracking tracks tracked
+# master does not track anything
+# all three point at different commits
+
+test_rev_equivalent () {
+
+	git rev-parse "$1" > expect &&
+	git rev-parse "$2" > output &&
+	test_cmp expect output
+
+}
+
+test_expect_success '%trackingbranch works' '
+	test_rev_equivalent tracked %tracking
+'
+
+test_expect_success '% works in tracking branch' '
+	git checkout tracking &&
+	test_rev_equivalent tracked %
+'
+
+test_expect_success '%nontrackingbranch fails' '
+	test_must_fail git rev-parse %tracked
+'
+
+test_expect_success '% fails in non-tracking branch' '
+	git checkout tracked &&
+	test_must_fail git rev-parse %
+'
+
+test_done
+
+
-- 
1.6.2.149.g6462
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 25 of 61 in “Re: Git {log,diff} against tracked branch?”
  1. Petr BaudisMar 18, 2009
  2. Introduce %<branch> as shortcut to the tracked branchJohannes Schindelin, Mar 18, 2009
  3. Andreas GruenbacherMar 18, 2009
  4. Introduce %<branch> as shortcut to the tracked branchJohannes Schindelin, Mar 18, 2009
  5. Andreas GruenbacherMar 18, 2009
  6. Johannes SchindelinMar 18, 2009
  7. Junio C HamanoMar 18, 2009
  8. Johannes SchindelinMar 18, 2009
  9. Michael J GruberMar 19, 2009
  10. Michael J GruberMar 19, 2009
  11. Johannes SchindelinMar 20, 2009
  12. ref name troubles, was Re: [PATCH v2] Introduce %<branch> as shortcut to the tracked branchJohannes Schindelin, Mar 20, 2009
  13. Shawn O. PearceMar 20, 2009
  14. Shawn O. PearceMar 20, 2009
  15. Sverre RabbelierMar 20, 2009
  16. Introduce BEL<branch> as shortcut to the tracked branchJohannes Schindelin, Mar 20, 2009
  17. Wincent ColaiutaMar 20, 2009
  18. Johannes SchindelinMar 20, 2009
  19. Santi BéjarMar 20, 2009
  20. Andreas GruenbacherMar 20, 2009
  21. Matthieu MoyMar 20, 2009
  22. Johannes SchindelinMar 20, 2009
  23. Mikael MagnussonMar 20, 2009
  24. Johannes SchindelinMar 20, 2009
  25. Document and test the new % shotcut for the tracked branchMichael J Gruber, Mar 20, 2009
  26. Johannes SchindelinMar 20, 2009
  27. Michael J GruberMar 20, 2009
  28. Petr BaudisMar 20, 2009
  29. Johannes SchindelinMar 20, 2009
  30. Petr BaudisMar 22, 2009
  31. Michael J GruberMar 20, 2009
  32. Introduce %<branch> as shortcut to the tracked branchJohannes Schindelin, Mar 20, 2009
  33. Junio C HamanoMar 20, 2009
  34. Johannes SchindelinMar 20, 2009
  35. Junio C HamanoMar 20, 2009
  36. Jeff KingMar 20, 2009
  37. Julian PhillipsMar 20, 2009
  38. Jeff KingMar 20, 2009
  39. Julian PhillipsMar 20, 2009
  40. Sverre RabbelierMar 20, 2009
  41. Julian PhillipsMar 20, 2009
  42. Sverre RabbelierMar 20, 2009
  43. Andreas GruenbacherMar 21, 2009
  44. Miles BaderMar 21, 2009
  45. Julian PhillipsMar 21, 2009
  46. Julian PhillipsMar 21, 2009
  47. Björn SteinbrinkMar 20, 2009
  48. Jeff KingMar 20, 2009
  49. Junio C HamanoMar 20, 2009
  50. Johannes SchindelinMar 20, 2009
  51. Petr BaudisMar 20, 2009
  52. Johannes SchindelinMar 20, 2009
  53. Petr BaudisMar 20, 2009
  54. Johannes SchindelinMar 20, 2009
  55. Michael J GruberMar 20, 2009
  56. Johannes SchindelinMar 20, 2009
  57. Michael J GruberMar 20, 2009
  58. Junio C HamanoMar 20, 2009
  59. Daniel BarkalowMar 20, 2009
  60. Johannes SchindelinMar 20, 2009
  61. Junio C HamanoMar 21, 2009

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.