Merge branch 'sb/reset-recurse-submodules'
"git reset" learned "--recurse-submodules" option. * sb/reset-recurse-submodules: builtin/reset: add --recurse-submodules switch submodule.c: submodule_move_head works with broken submodules submodule.c: uninitialized submodules are ignored in recursive commands entry.c: submodule recursing: respect force flag correctly
This commit is contained in:
31
submodule.c
31
submodule.c
@ -1402,6 +1402,23 @@ int submodule_move_head(const char *path,
|
||||
int ret = 0;
|
||||
struct child_process cp = CHILD_PROCESS_INIT;
|
||||
const struct submodule *sub;
|
||||
int *error_code_ptr, error_code;
|
||||
|
||||
if (!is_submodule_initialized(path))
|
||||
return 0;
|
||||
|
||||
if (flags & SUBMODULE_MOVE_HEAD_FORCE)
|
||||
/*
|
||||
* Pass non NULL pointer to is_submodule_populated_gently
|
||||
* to prevent die()-ing. We'll use connect_work_tree_and_git_dir
|
||||
* to fixup the submodule in the force case later.
|
||||
*/
|
||||
error_code_ptr = &error_code;
|
||||
else
|
||||
error_code_ptr = NULL;
|
||||
|
||||
if (old && !is_submodule_populated_gently(path, error_code_ptr))
|
||||
return 0;
|
||||
|
||||
sub = submodule_from_path(null_sha1, path);
|
||||
|
||||
@ -1420,15 +1437,21 @@ int submodule_move_head(const char *path,
|
||||
absorb_git_dir_into_superproject("", path,
|
||||
ABSORB_GITDIR_RECURSE_SUBMODULES);
|
||||
} else {
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
strbuf_addf(&sb, "%s/modules/%s",
|
||||
char *gitdir = xstrfmt("%s/modules/%s",
|
||||
get_git_common_dir(), sub->name);
|
||||
connect_work_tree_and_git_dir(path, sb.buf);
|
||||
strbuf_release(&sb);
|
||||
connect_work_tree_and_git_dir(path, gitdir);
|
||||
free(gitdir);
|
||||
|
||||
/* make sure the index is clean as well */
|
||||
submodule_reset_index(path);
|
||||
}
|
||||
|
||||
if (old && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {
|
||||
char *gitdir = xstrfmt("%s/modules/%s",
|
||||
get_git_common_dir(), sub->name);
|
||||
connect_work_tree_and_git_dir(path, gitdir);
|
||||
free(gitdir);
|
||||
}
|
||||
}
|
||||
|
||||
prepare_submodule_repo_env_no_git_dir(&cp.env_array);
|
||||
|
Reference in New Issue
Block a user