Re: [PATCH 24/25] worktree move: accept destination as directory
On Wed, Apr 13, 2016 at 9:15 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
Show 20 quoted lines
> 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
> @@ -538,7 +538,13 @@ static int move_worktree(int ac, const char **av, const char *prefix)
> - if (file_exists(dst.buf))
> + if (is_directory(dst.buf))
> + /*
> + * keep going, dst will be appended after we get the
> + * source's absolute path
> + */
> + ;
> + else if (file_exists(dst.buf))
> die(_("target '%s' already exists"), av[1]);
> @@ -558,6 +564,17 @@ static int move_worktree(int ac, const char **av, const char *prefix)
> + if (is_directory(dst.buf)) {
> + const char *sep = strrchr(wt->path, '/');Does this need to take Windows into account? Perhaps git_find_last_dir_sep()?
Show 8 quoted lines
> +
> + if (!sep)
> + die(_("could not figure out destination name from '%s'"),
> + wt->path);
> + strbuf_addstr(&dst, sep);
> + if (file_exists(dst.buf))
> + die(_("target '%s' already exists"), dst.buf);
> + }