Skip to content

Commit 62985f7

Browse files
pcloudsgitster
authored andcommitted
worktree move: refuse to move worktrees with submodules
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 183426d commit 62985f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

builtin/worktree.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,27 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
525525
return ret;
526526
}
527527

528+
static void validate_no_submodules(const struct worktree *wt)
529+
{
530+
struct index_state istate = {0};
531+
int i, found_submodules = 0;
532+
533+
if (read_index_from(&istate, worktree_git_path(wt, "index")) > 0) {
534+
for (i = 0; i < istate.cache_nr; i++) {
535+
struct cache_entry *ce = istate.cache[i];
536+
537+
if (S_ISGITLINK(ce->ce_mode)) {
538+
found_submodules = 1;
539+
break;
540+
}
541+
}
542+
}
543+
discard_index(&istate);
544+
545+
if (found_submodules)
546+
die(_("This working tree contains submodules and cannot be moved yet"));
547+
}
548+
528549
static int move_worktree(int ac, const char **av, const char *prefix)
529550
{
530551
struct option options[] = {
@@ -565,6 +586,8 @@ static int move_worktree(int ac, const char **av, const char *prefix)
565586
if (validate_worktree(wt, 0))
566587
return -1;
567588

589+
validate_no_submodules(wt);
590+
568591
if (is_directory(dst.buf)) {
569592
const char *sep = find_last_dir_sep(wt->path);
570593

0 commit comments

Comments
 (0)