[PATCH 20/22] checkout_submodule: checkout submodule on forced checkout of submodule dir
From: Sven Verdoolaege <skimo@kotnet.org>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
---
entry.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/entry.c b/entry.c
index f3e0c59..9c093ac 100644
--- a/entry.c
+++ b/entry.c
@@ -82,10 +82,20 @@ static int checkout_submodule(struct cache_entry *ce, const char *path, const st
const char *args[10];
int argc;
int err;
+ struct stat st;
+ char *gitdir;
- if (!state->submodules && !is_checkedout_submodule(ce->name))
+ if (!state->force && !is_checkedout_submodule(ce->name))
return 0;
+ gitdir = mkpath("%s/.git", ce->name);
+ if (lstat(gitdir, &st)) {
+ if (clone_submodule(ce->name))
+ return -1;
+ if (attach_submodule(ce->name))
+ return -1;
+ }
+
argc = 0;
args[argc++] = "checkout";
if (state->force)
@@ -220,6 +230,13 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
if (!lstat(path, &st)) {
unsigned changed = ce_match_stat(ce, &st, 1);
+ /*
+ * If submodule has not been checked out, then force
+ * forces a check-out.
+ */
+ if (state->force && S_ISGITLINK(ntohl(ce->ce_mode)) &&
+ !is_checkedout_submodule(ce->name))
+ changed = 1;
if (!changed)
return 0;
if (!state->force) {
--
1.5.2.784.g5532e