From c64a8d200f4109df86c6d4716ea4da58df450e34 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Mon, 12 Feb 2018 16:49:37 +0700 Subject: worktree move: accept destination as directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- builtin/worktree.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'builtin/worktree.c') diff --git a/builtin/worktree.c b/builtin/worktree.c index 8b9482d1e5..6fe41313c9 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) { -- cgit v1.2.3