diff mbox series

[v7,3/3] branch: Add an extra verbose output displaying worktree path for refs checked out in a linked worktree

Message ID 20190201220420.36216-4-nbelakovski@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v7,1/3] ref-filter: add worktreepath atom | expand

Commit Message

Nickolai Belakovski Feb. 1, 2019, 10:04 p.m. UTC
From: Nickolai Belakovski <nbelakovski@gmail.com>

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

Comments

Eric Sunshine Feb. 1, 2019, 10:27 p.m. UTC | #1
On Fri, Feb 1, 2019 at 5:04 PM <nbelakovski@gmail.com> wrote:
> Subject: branch: Add an extra verbose output displaying worktree path for refs checked out in a linked worktree

Overlong subject. Perhaps shorten it to:

    branch: display worktree path in -v -v mode

or something, and use the longer description as the rest of the body
of the commit message.

> Signed-off-by: Nickolai Belakovski <nbelakovski@gmail.com>
> ---
> diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
> @@ -167,8 +167,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 applicable (not applicable
> +       for main worktree since user's path will already be in main
> +       worktree) and the name of the upstream branch, as well (see also
> +       `git remote show <remote>`).

I'm not sure I understand the "not applicable" explanation. When you
say "user's path", do you mean the current working directory? What
happens if the command is invoked from within one of the linked
worktrees (not from within the main worktree)?
Nickolai Belakovski Feb. 1, 2019, 10:45 p.m. UTC | #2
On Fri, Feb 1, 2019 at 2:28 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> On Fri, Feb 1, 2019 at 5:04 PM <nbelakovski@gmail.com> wrote:
> > Subject: branch: Add an extra verbose output displaying worktree path for refs checked out in a linked worktree
>
> Overlong subject. Perhaps shorten it to:
>
>     branch: display worktree path in -v -v mode
>
> or something, and use the longer description as the rest of the body
> of the commit message.

OK

>
> > Signed-off-by: Nickolai Belakovski <nbelakovski@gmail.com>
> > ---
> > diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
> > @@ -167,8 +167,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 applicable (not applicable
> > +       for main worktree since user's path will already be in main
> > +       worktree) and the name of the upstream branch, as well (see also
> > +       `git remote show <remote>`).
>
> I'm not sure I understand the "not applicable" explanation. When you
> say "user's path", do you mean the current working directory? What
> happens if the command is invoked from within one of the linked
> worktrees (not from within the main worktree)?

I should correct that to say "current worktree" as opposed to main,
since that's what HEAD will give. And yes user's path means cwd. Does
that make more sense?
Junio C Hamano Feb. 1, 2019, 10:53 p.m. UTC | #3
nbelakovski@gmail.com writes:

> @@ -167,8 +167,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 applicable (not applicable
> +	for main worktree since user's path will already be in main
> +	worktree) and the name of the upstream branch, as well (see also
> +	`git remote show <remote>`).

It is unclear what you mean by "user's path"; I take it as the
$(pwd) at least for now for the purpose of this review, but then
I am not sure if I agree with that justification part "since..."

If I start from a normal repository at /home/gitster/main.git,
create a linked worktree of it at /home/gitster/alt.git, chdir to
/home/gitster/alt.git and ask "git branch -v -v", then the branch
that is checked out in the main.git "main worktree" is not shown?

If the rule were "a branch that is checked out in one of the
worktrees connected to the repository is shown with the path to that
worktree" (i.e. no exception), I would understand it.  If the rule
were "a branch that is ... (the same sentence), unless it is the
branch that is checked out in the *current* worktree", then I would
understand it too.

Puzzled.

In any case, please add a test or two to protect this feature from
unintended future breakages.

Thanks.

>  
>  -q::
>  --quiet::
> diff --git a/builtin/branch.c b/builtin/branch.c
> index c2a86362bb..0b8ba9e4c5 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)");
Nickolai Belakovski Feb. 1, 2019, 11:06 p.m. UTC | #4
On Fri, Feb 1, 2019 at 2:54 PM Junio C Hamano <gitster@pobox.com> wrote:

>
> If the rule were "a branch that is checked out in one of the
> worktrees connected to the repository is shown with the path to that
> worktree" (i.e. no exception), I would understand it.  If the rule
> were "a branch that is ... (the same sentence), unless it is the
> branch that is checked out in the *current* worktree", then I would
> understand it too.
>

It is the latter, as in, yes, I meant "current". I will update the docs as such.

>
> In any case, please add a test or two to protect this feature from
> unintended future breakages.
>
> Thanks.
>

Will do.
diff mbox series

Patch

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index b3eca6ffdc..778be7080f 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -167,8 +167,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 applicable (not applicable
+	for main worktree since user's path will already be in main
+	worktree) and the name of the upstream branch, as well (see also
+	`git remote show <remote>`).
 
 -q::
 --quiet::
diff --git a/builtin/branch.c b/builtin/branch.c
index c2a86362bb..0b8ba9e4c5 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)");