diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2018-02-12 10:49:37 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-02-12 22:13:35 +0100 |
commit | c64a8d200f4109df86c6d4716ea4da58df450e34 (patch) | |
tree | eaf8198f7aa5a888178e7a807dcc482c988b30fe /builtin/worktree.c | |
parent | worktree move: new command (diff) | |
download | git-c64a8d200f4109df86c6d4716ea4da58df450e34.tar.xz git-c64a8d200f4109df86c6d4716ea4da58df450e34.zip |
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r-- | builtin/worktree.c | 11 |
1 files changed, 10 insertions, 1 deletions
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) { |