branch: add worktree info on verbose output

To display worktree path for refs checked out in a linked worktree Signed-off-by: Nickolai Belakovski <nbelakovski@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nickolai Belakovski committed Apr 28, 2019 at 22:19 UTC 6e9381469e3bd866e73affe6d9d96206ee7ff965
3 files changed +27 -2
Documentation/git-branch.txt
+4 -2
@@ -172,8 +172,10 @@ This option is only applicable in non-verbose mode.
172 When in list mode,
173 show sha1 and commit subject line for each head, along with
174 relationship to upstream branch (if any). If given twice, print
175 - the name of the upstream branch, as well (see also `git remote
176 - show <remote>`).
175 + the path of the linked worktree (if any) and the name of the upstream
176 + branch, as well (see also `git remote show <remote>`). Note that the
177 + current worktree's HEAD will not have its path printed (it will always
178 + be your current directory).
179
180 -q::
181 --quiet::
builtin/branch.c
+4
@@ -367,9 +367,13 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
367 strbuf_addf(&local, " %s ", obname.buf);
368
369 if (filter->verbose > 1)
370 + {
371 + strbuf_addf(&local, "%%(if:notequals=*)%%(HEAD)%%(then)%%(if)%%(worktreepath)%%(then)(%s%%(worktreepath)%s) %%(end)%%(end)",
372 + branch_get_color(BRANCH_COLOR_WORKTREE), branch_get_color(BRANCH_COLOR_RESET));
373 strbuf_addf(&local, "%%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s%%(if)%%(upstream:track)"
374 "%%(then): %%(upstream:track,nobracket)%%(end)] %%(end)%%(contents:subject)",
375 branch_get_color(BRANCH_COLOR_UPSTREAM), branch_get_color(BRANCH_COLOR_RESET));
376 + }
377 else
378 strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
379
t/t3203-branch-output.sh
+19
@@ -328,4 +328,23 @@ test_expect_success '--color overrides auto-color' '
328 test_cmp expect.color actual
329 '
330
331 +test_expect_success 'verbose output lists worktree path' '
332 + one=$(git rev-parse --short HEAD) &&
333 + two=$(git rev-parse --short master) &&
334 + cat >expect <<-EOF &&
335 + * (HEAD detached from fromtag) $one one
336 + ambiguous $one one
337 + branch-one $two two
338 + + branch-two $one ($(pwd)/worktree_dir) one
339 + master $two two
340 + ref-to-branch $two two
341 + ref-to-remote $two two
342 + EOF
343 + git worktree add worktree_dir branch-two &&
344 + git branch -vv >actual &&
345 + rm -r worktree_dir &&
346 + git worktree prune &&
347 + test_i18ncmp expect actual
348 +'
349 +
350 test_done