path: root/builtin/worktree.c
diff options
authorNguyễn Thái Ngọc Duy <>2018-02-12 09:49:37 (GMT)
committerJunio C Hamano <>2018-02-12 21:13:35 (GMT)
commitc64a8d200f4109df86c6d4716ea4da58df450e34 (patch)
treeeaf8198f7aa5a888178e7a807dcc482c988b30fe /builtin/worktree.c
parent9f792bb4721066ce27ee98c4ad38d6d146b64fcf (diff)
worktree move: accept destination as directory
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/worktree.c')
1 files changed, 10 insertions, 1 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 8b9482d..6fe4131 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -631,8 +631,17 @@ 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_trim_trailing_dir_sep(&dst);
+ strbuf_addstr(&dst, sep);
+ }
if (file_exists(dst.buf))
- die(_("target '%s' already exists"), av[1]);
+ die(_("target '%s' already exists"), dst.buf);
reason = is_worktree_locked(wt);
if (reason) {