From 7f5607439ed0d1303265d3db0937e90683e698de Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 31 Mar 2016 12:30:42 -0400 Subject: 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. --- Source/CTest/cmCTestGIT.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 9ee18e6..1d6bdce 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -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()); -- cgit v0.12