Commit 7f560743 authored by Ben Boeckel's avatar Ben Boeckel Committed by Brad King

cmCTestGIT: run `git submodule sync` before updating submodules

If the URL of a submodule changes upstream, the commits referenced at
the old URL may not be available and will cause an update failure.
parent 06b310b5
......@@ -273,6 +273,7 @@ bool cmCTestGIT::UpdateImpl()
std::string top_dir = this->FindTopDir();
const char* git = this->CommandLineTool.c_str();
const char* recursive = "--recursive";
const char* sync_recursive = "--recursive";
// Git < 1.6.5 did not support submodule --recursive
if(this->GetGitVersion() < cmCTestGITVersion(1,6,5,0))
......@@ -285,6 +286,17 @@ bool cmCTestGIT::UpdateImpl()
}
}
// Git < 1.8.1 did not support sync --recursive
if(this->GetGitVersion() < cmCTestGITVersion(1,8,1,0))
{
sync_recursive = 0;
// No need to require >= 1.8.1 if there are no submodules.
if(cmSystemTools::FileExists((top_dir + "/.gitmodules").c_str()))
{
this->Log << "Git < 1.8.1 cannot synchronize submodules recursively\n";
}
}
OutputLogger submodule_out(this->Log, "submodule-out> ");
OutputLogger submodule_err(this->Log, "submodule-err> ");
......@@ -304,6 +316,16 @@ bool cmCTestGIT::UpdateImpl()
}
}
char const* git_submodule_sync[] = {git, "submodule", "sync",
sync_recursive, 0};
ret = this->RunChild(git_submodule_sync, &submodule_out, &submodule_err,
top_dir.c_str());
if (!ret)
{
return false;
}
char const* git_submodule[] = {git, "submodule", "update", recursive, 0};
return this->RunChild(git_submodule, &submodule_out, &submodule_err,
top_dir.c_str());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment