* Moves a submodule at a given path from a given head to another new head. * For edge cases (a submodule coming into existence or removing a submodule) * pass NULL for old or new respectively. */
| 2124 | * pass NULL for old or new respectively. |
| 2125 | */ |
| 2126 | int submodule_move_head(const char *path, const char *super_prefix, |
| 2127 | const char *old_head, const char *new_head, |
| 2128 | unsigned flags) |
| 2129 | { |
| 2130 | int ret = 0; |
| 2131 | struct child_process cp = CHILD_PROCESS_INIT; |
| 2132 | const struct submodule *sub; |
| 2133 | int *error_code_ptr, error_code; |
| 2134 | |
| 2135 | if (!is_submodule_active(the_repository, path)) |
| 2136 | return 0; |
| 2137 | |
| 2138 | if (flags & SUBMODULE_MOVE_HEAD_FORCE) |
| 2139 | /* |
| 2140 | * Pass non NULL pointer to is_submodule_populated_gently |
| 2141 | * to prevent die()-ing. We'll use connect_work_tree_and_git_dir |
| 2142 | * to fixup the submodule in the force case later. |
| 2143 | */ |
| 2144 | error_code_ptr = &error_code; |
| 2145 | else |
| 2146 | error_code_ptr = NULL; |
| 2147 | |
| 2148 | if (old_head && !is_submodule_populated_gently(path, error_code_ptr)) |
| 2149 | return 0; |
| 2150 | |
| 2151 | sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); |
| 2152 | |
| 2153 | if (!sub) |
| 2154 | BUG("could not get submodule information for '%s'", path); |
| 2155 | |
| 2156 | if (old_head && !(flags & SUBMODULE_MOVE_HEAD_FORCE)) { |
| 2157 | /* Check if the submodule has a dirty index. */ |
| 2158 | if (submodule_has_dirty_index(sub)) |
| 2159 | return error(_("submodule '%s' has dirty index"), path); |
| 2160 | } |
| 2161 | |
| 2162 | if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) { |
| 2163 | if (old_head) { |
| 2164 | if (!submodule_uses_gitfile(path)) |
| 2165 | absorb_git_dir_into_superproject(path, |
| 2166 | super_prefix); |
| 2167 | else { |
| 2168 | char *dotgit = xstrfmt("%s/.git", path); |
| 2169 | char *git_dir = xstrdup(read_gitfile(dotgit)); |
| 2170 | |
| 2171 | free(dotgit); |
| 2172 | if (validate_submodule_git_dir(git_dir, |
| 2173 | sub->name) < 0) |
| 2174 | die(_("refusing to create/use '%s' in " |
| 2175 | "another submodule's git dir. " |
| 2176 | "Enabling extensions.submodulePathConfig " |
| 2177 | "should fix this."), git_dir); |
| 2178 | free(git_dir); |
| 2179 | } |
| 2180 | } else { |
| 2181 | struct strbuf gitdir = STRBUF_INIT; |
| 2182 | submodule_name_to_gitdir(&gitdir, the_repository, |
| 2183 | sub->name); |
no test coverage detected