Skip to content
Snippets Groups Projects
Commit 2453ccbf authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

Sync submodules when checking out a Repository.

parent 3204a137
No related branches found
No related tags found
No related merge requests found
......@@ -128,7 +128,7 @@ public class Repository {
return !failed;
};
return checkout.map(toBoolean).orElse(false);
return checkout.map(toBoolean).map(co -> co && syncSubmodules()).orElse(false);
}
/**
......@@ -152,7 +152,33 @@ public class Repository {
return true;
};
return checkout.map(toBoolean).orElse(false);
return checkout.map(toBoolean).map(co -> co && syncSubmodules()).orElse(false);
}
/**
* Synchronizes and initializes the submodules of this repository.
*
* @return whether the synchronization was successful
*/
private Boolean syncSubmodules() {
Optional<ExecRes> init = git.exec(dir, "submodule", "init");
Optional<ExecRes> sync = init.filter(ExecRes::succeeded)
.flatMap(res -> git.exec(dir, "submodule", "sync"));
Optional<ExecRes> update = sync.filter(ExecRes::succeeded)
.flatMap(res -> git.exec(dir, "submodule", "update", "--init", "--recursive"));
Function<ExecRes, Boolean> toBoolean = res -> {
boolean failed = git.failed(res);
if (failed) {
LOG.warning(() -> "Failed to sync the submodules of " + Repository.this);
return false;
}
return true;
};
return update.map(toBoolean).orElse(false);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment