On Sun, Apr 15, 2018 at 4:29 PM, Thomas Gummerer <[email protected]> wrote:
> Currently 'git worktree add' produces output like the following:
>
> Preparing ../foo (identifier foo)
> HEAD is now at 26da330922 <title>
> [...]
> Instead of this message, print a message that gives the user a bit more
> detail of what exactly 'git worktree' is doing. There are various dwim
> modes which are perform some magic under the hood, which should be
> helpful to users. Just from the output of the command it is not always
> visible to users what exactly has happened.
>
> Help the users a bit more by modifying the "Preparing ..." message and
> adding some additional information of what 'git worktree add' did under
> the hood, while not displaying the identifier anymore.
>
> Currently this ends up in three different cases:
>
> - 'git worktree add -b ...' or 'git worktree add <path>' [...]
>
> - 'git worktree add -B ...', which may either create a new branch if
> the branch with the given name does not exist yet, or resets an
> existing branch to the current HEAD, or the commit-ish given.
> Depending on which action is taken, we'll end up with the following
> output:
>
> Preparing worktree (resetting branch 'next' (was at caa68db14))
> HEAD is now at 26da330922 <title>
The (...) embedded inside another (...) is ugly and hard to read.
Better perhaps:
Preparing worktree (resetting branch 'next'; was at caa68db14)
Not necessarily worth a re-roll. It would be nice to see this series
land; perhaps this can be tweaked later.
> or:
>
> Preparing worktree (new branch '<branch>')
> HEAD is now at 26da330922 <title>
>
> - 'git worktree add --detach' or 'git worktree add <path> <branch>',
> both of which create a new worktree with a detached HEAD, for which
> we will print the following output:
>
> Preparing worktree (detached HEAD 26da330922)
> HEAD is now at 26da330922 <title>
This is inaccurate, isn't it? Certainly, specifying something like
"origin/floop" for <branch> ends up detached:
% git worktree add w1 origin/floop
...
% git worktree list
/proj fe0a9eaf31 [master]
/proj/w1 b46fe60e1d (detached HEAD)
but specifying an existing local branch (say "wip") does not end up detached:
% git worktree add w2 wip
...
% git worktree list
/proj fe0a9eaf31 [master]
/proj/w1 b46fe60e1d (detached HEAD)
/proj/w2 820ed2a513 [wip]
> Additionally currently the "Preparing ..." line is printed to stderr,
> while the "HEAD is now at ..." line is printed to stdout by 'git reset
> --hard', which is used internally by 'git worktree add'. Fix this
> inconsistency by printing the "Preparing ..." message to stdout as
> well. As "Preparing ..." is not an error, stdout also seems like the
> more appropriate output stream.
>
> Helped-by: Eric Sunshine <[email protected]>
> Signed-off-by: Thomas Gummerer <[email protected]>