All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: Git List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Subject: Re: [PATCH 4/7] worktree move: accept destination as directory
Date: Fri, 2 Feb 2018 04:35:17 -0500	[thread overview]
Message-ID: <CAPig+cTAmzAK2vQHuPHJJMT+Q2fiD4P--qv_rSrc2gKbFFhPTg@mail.gmail.com> (raw)
In-Reply-To: <20180124095357.19645-5-pclouds@gmail.com>

On Wed, Jan 24, 2018 at 4:53 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> Similar to "mv a b/", which is actually "mv a b/a", we extract basename
> of source worktree and create a directory of the same name at
> destination if dst path is a directory.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -624,8 +624,6 @@ static int move_worktree(int ac, const char **av, const char *prefix)
>         path = prefix_filename(prefix, av[1]);
>         strbuf_addstr(&dst, path);
>         free(path);
> -       if (file_exists(dst.buf))
> -               die(_("target '%s' already exists"), av[1]);

Nit: The distance between this "removed" conditional and the code
inserted below hampered review a bit since it made it slightly more
onerous to check for unwanted logic changes. Had patch 3/7 located
this conditional below the is_main_worktree() check (where the new
code is inserted below), this 'if' would have merely mutated into an
'else if' but not otherwise moved, thus review would have been
simplified. (Not itself worth a re-roll.)

>         worktrees = get_worktrees(0);
>         wt = find_worktree(worktrees, prefix, av[0]);
> @@ -633,6 +631,20 @@ static int move_worktree(int ac, const char **av, const char *prefix)
>                 die(_("'%s' is not a working tree"), av[0]);
>         if (is_main_worktree(wt))
>                 die(_("'%s' is a main working tree"), av[0]);
> +
> +       if (is_directory(dst.buf)) {
> +               const char *sep = find_last_dir_sep(wt->path);
> +
> +               if (!sep)
> +                       die(_("could not figure out destination name from '%s'"),
> +                           wt->path);
> +               strbuf_addstr(&dst, sep);

Do we know at this point whether 'dst' has a terminating "/"? If it
does, then this addstr() could result in "//" in the path which might
be problematic on Windows.

> +               if (file_exists(dst.buf))
> +                       die(_("target '%s' already exists"), dst.buf);
> +       } else if (file_exists(dst.buf)) {
> +               die(_("target '%s' already exists"), av[1]);
> +       }

I wonder if it makes sense to collapse the duplicated
file_exists()/"target already exists" code?

    if (is_directory(...)) {
        ...
        strbuf_addstr(&dst, sep);
    }
    if (file_exists(dst.buf))
        die(_("target '%s' already exists"), dst.buf);

It changes the error message slightly for the non-directory case but
simplifies the code a bit.

>         reason = is_worktree_locked(wt);
>         if (reason) {
>                 if (*reason)

Perhaps add a test to t2028-worktree-move.sh to show that this new
behavior works?

  reply	other threads:[~2018-02-02  9:35 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24  9:53 [PATCH 0/7] nd/worktree-move reboot Nguyễn Thái Ngọc Duy
2018-01-24  9:53 ` [PATCH 1/7] worktree.c: add validate_worktree() Nguyễn Thái Ngọc Duy
2018-01-24  9:53 ` [PATCH 2/7] worktree.c: add update_worktree_location() Nguyễn Thái Ngọc Duy
2018-02-02  8:23   ` Eric Sunshine
2018-02-02  9:35     ` Duy Nguyen
2018-01-24  9:53 ` [PATCH 3/7] worktree move: new command Nguyễn Thái Ngọc Duy
2018-02-02  9:15   ` Eric Sunshine
2018-02-02 11:23     ` Eric Sunshine
2018-02-05 13:28       ` Duy Nguyen
2018-02-06  2:13         ` Jeff King
2018-02-06 20:05           ` Martin Ågren
2018-02-12  9:56             ` Duy Nguyen
2018-02-12 22:15               ` Martin Ågren
2018-02-13  0:27                 ` Duy Nguyen
2018-02-14  3:16                   ` Jeff King
2018-02-14  9:07                     ` Duy Nguyen
2018-02-14 17:35                       ` Junio C Hamano
2018-02-14 21:56                         ` [PATCH] t/known-leaky: add list of known-leaky test scripts Martin Ågren
2018-02-19 21:29                           ` Jeff King
2018-02-20 20:44                             ` Martin Ågren
2018-02-20 21:08                               ` Jeff King
2018-02-21 16:53                               ` Junio C Hamano
2018-02-21 18:25                                 ` Jeff King
2018-02-25  3:48                               ` Kaartic Sivaraam
2018-02-26 21:22                                 ` Martin Ågren
2018-01-24  9:53 ` [PATCH 4/7] worktree move: accept destination as directory Nguyễn Thái Ngọc Duy
2018-02-02  9:35   ` Eric Sunshine [this message]
2018-01-24  9:53 ` [PATCH 5/7] worktree move: refuse to move worktrees with submodules Nguyễn Thái Ngọc Duy
2018-02-02 10:06   ` Eric Sunshine
2018-01-24  9:53 ` [PATCH 6/7] worktree remove: new command Nguyễn Thái Ngọc Duy
2018-02-02 11:47   ` Eric Sunshine
2018-02-12  9:26     ` Duy Nguyen
2018-01-24  9:53 ` [PATCH 7/7] worktree remove: allow it when $GIT_WORK_TREE is already gone Nguyễn Thái Ngọc Duy
2018-02-02 12:59   ` Eric Sunshine
2018-01-24 20:42 ` [PATCH 0/7] nd/worktree-move reboot Junio C Hamano
2018-02-12  9:49 ` [PATCH v2 " Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 1/7] worktree.c: add validate_worktree() Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 2/7] worktree.c: add update_worktree_location() Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 3/7] worktree move: new command Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 4/7] worktree move: accept destination as directory Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 5/7] worktree move: refuse to move worktrees with submodules Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 6/7] worktree remove: new command Nguyễn Thái Ngọc Duy
2018-02-12  9:49   ` [PATCH v2 7/7] worktree remove: allow it when $GIT_WORK_TREE is already gone Nguyễn Thái Ngọc Duy
2018-03-04  5:26   ` [PATCH] t2028: fix minor error and issues in newly-added "worktree move" tests Eric Sunshine
2018-03-05  9:32     ` Duy Nguyen
2018-03-05 12:48     ` SZEDER Gábor
2018-03-05 18:37       ` Junio C Hamano
2018-03-05 18:44         ` Eric Sunshine
2018-03-04  5:36   ` [PATCH v2 0/7] nd/worktree-move reboot 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=CAPig+cTAmzAK2vQHuPHJJMT+Q2fiD4P--qv_rSrc2gKbFFhPTg@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=pclouds@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.