Re: [PATCH 24/25] worktree move: accept destination as directory
flat view
From: Eric Sunshine <hidden>
Date: 2016-06-16 02:19:18
On Wed, Apr 13, 2016 at 9:15 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted> ---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()?
quoted hunk ↗ jump to hunk
+ + 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); + }