Skip to content

Commit 6e93814

Browse files
nbelakovskigitster
authored andcommitted
branch: add worktree info on verbose output
To display worktree path for refs checked out in a linked worktree Signed-off-by: Nickolai Belakovski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab31381 commit 6e93814

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Documentation/git-branch.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ This option is only applicable in non-verbose mode.
172172
When in list mode,
173173
show sha1 and commit subject line for each head, along with
174174
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).
177179

178180
-q::
179181
--quiet::

builtin/branch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,13 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
367367
strbuf_addf(&local, " %s ", obname.buf);
368368

369369
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));
370373
strbuf_addf(&local, "%%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s%%(if)%%(upstream:track)"
371374
"%%(then): %%(upstream:track,nobracket)%%(end)] %%(end)%%(contents:subject)",
372375
branch_get_color(BRANCH_COLOR_UPSTREAM), branch_get_color(BRANCH_COLOR_RESET));
376+
}
373377
else
374378
strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
375379

t/t3203-branch-output.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,23 @@ test_expect_success '--color overrides auto-color' '
328328
test_cmp expect.color actual
329329
'
330330

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+
331350
test_done

0 commit comments

Comments
 (0)