git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: Pratyush Yadav <me@yadavpratyush.com>
Cc: git@vger.kernel.org, Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH] worktree: add shorthand '-d' for detach
Date: Mon, 27 Jan 2020 13:26:10 +0100	[thread overview]
Message-ID: <20200127122610.GB10482@szeder.dev> (raw)
In-Reply-To: <20200125173744.4334-1-me@yadavpratyush.com>

On Sat, Jan 25, 2020 at 11:07:44PM +0530, Pratyush Yadav wrote:
> Often someone might want to checkout an older commit in a separate
> worktree to test it out without having any intention of making any
> changes. Simply using 'git worktree add' means that a branch will be
> created based on the name of the worktree folder. This branch will then
> have to be deleted by the user once they are done with the worktree.
> 
> An alternative to this is to create a detached worktree which doesn't
> lead to a branch being created. This can be done by the '--detach'
> option. Add the shorthand to make it more convenient to use it.

I don't really understand what this commit message is trying to say,
especially the first paragraph, or how it relates to adding short
options.

It could just say something along the lines of "'git worktree add' has
a couple of long --options without corresponding -o short options, you
wanted to type less, so let's add those missing short options."

But then why only '--detach', and not the other long --options as
well?


> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
> ---
> For more context:
> https://lore.kernel.org/git/CAPig+cQmqKiYWDWFH5eK2S6XPOi2t2+8Oas8yZa8R=bKLym3wQ@mail.gmail.com/
> 
> I'll send a patch to add the config option as a follow up some time
> later.
> 
>  Documentation/git-worktree.txt | 7 ++++---
>  builtin/worktree.c             | 2 +-
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
> index 85d92c9761..cc227dd382 100644
> --- a/Documentation/git-worktree.txt
> +++ b/Documentation/git-worktree.txt
> @@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
>  SYNOPSIS
>  --------
>  [verse]
> -'git worktree add' [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]
> +'git worktree add' [-f] [-d] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]

'--detach' is still an accepted options, so please write it as
'[-d|--detach]' instead.

While at it, you might want to break this line, as it got too long.

>  'git worktree list' [--porcelain]
>  'git worktree lock' [--reason <string>] <worktree>
>  'git worktree move' <worktree> <new-path>
> @@ -52,7 +52,7 @@ directory specific files such as HEAD, index, etc. `-` may also be
>  specified as `<commit-ish>`; it is synonymous with `@{-1}`.
>  +
>  If <commit-ish> is a branch name (call it `<branch>`) and is not found,
> -and neither `-b` nor `-B` nor `--detach` are used, but there does
> +and neither `-b` nor `-B` nor `-d` are used, but there does

Here I would prefer to keep '--detach', because "detach" is a real
word with proper meaning, while 'd' is just an abbreviation.

>  exist a tracking branch in exactly one remote (call it `<remote>`)
>  with a matching name, treat as equivalent to:
>  +
> @@ -69,7 +69,7 @@ branches from there if `<branch>` is ambiguous but exists on the
>  'origin' remote. See also `checkout.defaultRemote` in
>  linkgit:git-config[1].
>  +
> -If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `--detach` used,
> +If `<commit-ish>` is omitted and neither `-b` nor `-B` nor `-d` used,

Likewise.

>  then, as a convenience, the new worktree is associated with a branch
>  (call it `<branch>`) named after `$(basename <path>)`.  If `<branch>`
>  doesn't exist, a new branch based on HEAD is automatically created as
> @@ -140,6 +140,7 @@ To remove a locked working tree, specify `--force` twice.
>  	exists. `-B` overrides this safeguard, resetting `<new-branch>` to
>  	`<commit-ish>`.
> 
> +-d::
>  --detach::
>  	With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
>  	in linkgit:git-checkout[1].
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index d6bc5263f1..dab5f76788 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -500,7 +500,7 @@ static int add(int ac, const char **av, const char *prefix)
>  			   N_("create a new branch")),
>  		OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
>  			   N_("create or reset a branch")),
> -		OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
> +		OPT_BOOL('d', "detach", &opts.detach, N_("detach HEAD at named commit")),
>  		OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
>  		OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
>  		OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),
> --
> 2.24.1
> 

  reply	other threads:[~2020-01-27 12:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-25 17:37 [PATCH] worktree: add shorthand '-d' for detach Pratyush Yadav
2020-01-27 12:26 ` SZEDER Gábor [this message]
2020-01-27 16:05   ` Eric Sunshine
2020-01-27 20:31     ` Junio C Hamano
2020-01-27 16:28 ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200127122610.GB10482@szeder.dev \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@yadavpratyush.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).