From 78d986b252359351a579dc2629c8384d5c8eb8ff Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Mon, 12 Feb 2018 16:49:38 +0700 Subject: worktree move: refuse to move worktrees with submodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Submodules contains .git files with relative paths. After a worktree move, these files need to be updated or they may point to nowhere. This is a bandage patch to make sure "worktree move" don't break people's worktrees by accident. When .git file update code is in place, this validate_no_submodules() could be removed. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/worktree.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'builtin/worktree.c') diff --git a/builtin/worktree.c b/builtin/worktree.c index 6fe41313c9..4789cebe11 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -606,6 +606,27 @@ static int unlock_worktree(int ac, const char **av, const char *prefix) return ret; } +static void validate_no_submodules(const struct worktree *wt) +{ + struct index_state istate = { NULL }; + int i, found_submodules = 0; + + if (read_index_from(&istate, worktree_git_path(wt, "index")) > 0) { + for (i = 0; i < istate.cache_nr; i++) { + struct cache_entry *ce = istate.cache[i]; + + if (S_ISGITLINK(ce->ce_mode)) { + found_submodules = 1; + break; + } + } + } + discard_index(&istate); + + if (found_submodules) + die(_("working trees containing submodules cannot be moved")); +} + static int move_worktree(int ac, const char **av, const char *prefix) { struct option options[] = { @@ -643,6 +664,8 @@ static int move_worktree(int ac, const char **av, const char *prefix) if (file_exists(dst.buf)) die(_("target '%s' already exists"), dst.buf); + validate_no_submodules(wt); + reason = is_worktree_locked(wt); if (reason) { if (*reason) -- cgit v1.3-6-g1900