diff mbox series

[v9,3/3] branch: add worktree info on verbose output

Message ID 20190316013807.38756-4-nbelakovski@gmail.com (mailing list archive)
State New, archived
Headers show
Series | expand

Commit Message

Nickolai Belakovski March 16, 2019, 1:38 a.m. UTC
From: Nickolai Belakovski <nbelakovski@gmail.com>

To display worktree path for refs checked out in a linked worktree

Signed-off-by: Nickolai Belakovski <nbelakovski@gmail.com>
---
 Documentation/git-branch.txt |  6 ++++--
 builtin/branch.c             |  4 ++++
 t/t3203-branch-output.sh     | 19 +++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

Comments

SZEDER Gábor March 18, 2019, 12:10 p.m. UTC | #1
On Fri, Mar 15, 2019 at 06:38:07PM -0700, nbelakovski@gmail.com wrote:
> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
> index ceb74e0826..e5dc23e225 100755
> --- a/t/t3203-branch-output.sh
> +++ b/t/t3203-branch-output.sh
> @@ -328,4 +328,23 @@ test_expect_success '--color overrides auto-color' '
>  	test_cmp expect.color actual
>  '
>  
> +test_expect_success 'verbose output lists worktree path' '
> +	one=$(git rev-parse --short HEAD) &&
> +	two=$(git rev-parse --short master) &&
> +	cat >expect <<-EOF &&
> +	* (HEAD detached from fromtag) $one one

This 'HEAD detached from ..." message is translated ...

> +	  ambiguous                    $one one
> +	  branch-one                   $two two
> +	+ branch-two                   $one ($(pwd)/worktree_dir) one
> +	  master                       $two two
> +	  ref-to-branch                $two two
> +	  ref-to-remote                $two two
> +	EOF
> +	git worktree add worktree_dir branch-two &&
> +	git branch -vv >actual &&
> +	rm -r worktree_dir &&
> +	git worktree prune &&
> +	test_cmp expect actual

... therefore here you should use 'test_i18ncmp', as otherwise the
GETTEXT_POISON test run fails.

> +'
> +
>  test_done
> -- 
> 2.14.2
>
diff mbox series

Patch

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 7d18dffc4b..d11d00583a 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -172,8 +172,10 @@  This option is only applicable in non-verbose mode.
 	When in list mode,
 	show sha1 and commit subject line for each head, along with
 	relationship to upstream branch (if any). If given twice, print
-	the name of the upstream branch, as well (see also `git remote
-	show <remote>`).
+	the path of the linked worktree (if any) and the name of the upstream
+	branch, as well (see also `git remote show <remote>`).  Note that the
+	current worktree's HEAD will not have its path printed (it will always
+	be your current directory).
 
 -q::
 --quiet::
diff --git a/builtin/branch.c b/builtin/branch.c
index 350b039063..3d1872babc 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -367,9 +367,13 @@  static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
 		strbuf_addf(&local, " %s ", obname.buf);
 
 		if (filter->verbose > 1)
+		{
+			strbuf_addf(&local, "%%(if:notequals=*)%%(HEAD)%%(then)%%(if)%%(worktreepath)%%(then)(%s%%(worktreepath)%s) %%(end)%%(end)",
+				    branch_get_color(BRANCH_COLOR_WORKTREE), branch_get_color(BRANCH_COLOR_RESET));
 			strbuf_addf(&local, "%%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s%%(if)%%(upstream:track)"
 				    "%%(then): %%(upstream:track,nobracket)%%(end)] %%(end)%%(contents:subject)",
 				    branch_get_color(BRANCH_COLOR_UPSTREAM), branch_get_color(BRANCH_COLOR_RESET));
+		}
 		else
 			strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
 
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index ceb74e0826..e5dc23e225 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -328,4 +328,23 @@  test_expect_success '--color overrides auto-color' '
 	test_cmp expect.color actual
 '
 
+test_expect_success 'verbose output lists worktree path' '
+	one=$(git rev-parse --short HEAD) &&
+	two=$(git rev-parse --short master) &&
+	cat >expect <<-EOF &&
+	* (HEAD detached from fromtag) $one one
+	  ambiguous                    $one one
+	  branch-one                   $two two
+	+ branch-two                   $one ($(pwd)/worktree_dir) one
+	  master                       $two two
+	  ref-to-branch                $two two
+	  ref-to-remote                $two two
+	EOF
+	git worktree add worktree_dir branch-two &&
+	git branch -vv >actual &&
+	rm -r worktree_dir &&
+	git worktree prune &&
+	test_cmp expect actual
+'
+
 test_done