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.
This commit is contained in:
Ben Boeckel 2016-03-31 12:30:42 -04:00 committed by Brad King
parent 06b310b5d5
commit 7f5607439e
1 changed files with 22 additions and 0 deletions

View File

@ -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());