summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-05-29 12:34:40 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-05-29 12:34:40 +0900
commit5f074ca7e8ddccb6471e457d7a3f85c1fe00e21a (patch)
treebe3c66e879a0278947e30089b376434c6af3a5d8 /submodule.c
parentSecond batch for 2.14 (diff)
parentbuiltin/reset: add --recurse-submodules switch (diff)
downloadtgif-5f074ca7e8ddccb6471e457d7a3f85c1fe00e21a.tar.xz
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
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/submodule.c b/submodule.c
index 7eaa3d384e..54825100b2 100644
--- a/submodule.c
+++ b/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);