| 1201 | } |
| 1202 | |
| 1203 | static void validate_no_submodules(const struct worktree *wt) |
| 1204 | { |
| 1205 | struct index_state istate = INDEX_STATE_INIT(the_repository); |
| 1206 | struct strbuf path = STRBUF_INIT; |
| 1207 | int i, found_submodules = 0; |
| 1208 | char *wt_gitdir; |
| 1209 | |
| 1210 | wt_gitdir = get_worktree_git_dir(wt); |
| 1211 | |
| 1212 | if (is_directory(worktree_git_path(wt, "modules"))) { |
| 1213 | /* |
| 1214 | * There could be false positives, e.g. the "modules" |
| 1215 | * directory exists but is empty. But it's a rare case and |
| 1216 | * this simpler check is probably good enough for now. |
| 1217 | */ |
| 1218 | found_submodules = 1; |
| 1219 | } else if (read_index_from(&istate, worktree_git_path(wt, "index"), |
| 1220 | wt_gitdir) > 0) { |
| 1221 | for (i = 0; i < istate.cache_nr; i++) { |
| 1222 | struct cache_entry *ce = istate.cache[i]; |
| 1223 | int err; |
| 1224 | |
| 1225 | if (!S_ISGITLINK(ce->ce_mode)) |
| 1226 | continue; |
| 1227 | |
| 1228 | strbuf_reset(&path); |
| 1229 | strbuf_addf(&path, "%s/%s", wt->path, ce->name); |
| 1230 | if (!is_submodule_populated_gently(path.buf, &err)) |
| 1231 | continue; |
| 1232 | |
| 1233 | found_submodules = 1; |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
| 1237 | discard_index(&istate); |
| 1238 | strbuf_release(&path); |
| 1239 | free(wt_gitdir); |
| 1240 | |
| 1241 | if (found_submodules) |
| 1242 | die(_("working trees containing submodules cannot be moved or removed")); |
| 1243 | } |
| 1244 | |
| 1245 | static int move_worktree(int ac, const char **av, const char *prefix, |
| 1246 | struct repository *repo UNUSED) |
no test coverage detected