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 <pclouds@xxxxxxxxx> --- builtin/worktree.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/builtin/worktree.c b/builtin/worktree.c index f732a74..e36e4dc 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -525,6 +525,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 = {0}; + 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(_("This working tree contains submodules and cannot be moved yet")); +} + static int move_worktree(int ac, const char **av, const char *prefix) { struct option options[] = { @@ -565,6 +586,8 @@ static int move_worktree(int ac, const char **av, const char *prefix) if (validate_worktree(wt, 0)) return -1; + validate_no_submodules(wt); + if (is_directory(dst.buf)) { const char *sep = find_last_dir_sep(wt->path); -- 2.8.2.524.g6ff3d78