diff options
author | Brad King <brad.king@kitware.com> | 2011-02-22 20:47:50 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2011-02-22 20:47:50 (GMT) |
commit | 1173cc4ab2dc23a2ac51442273127d2f909f3bc8 (patch) | |
tree | 9dd12cb8433da2b9dad2aeaa7752745b346e2357 /Source/CTest/cmCTestGIT.cxx | |
parent | 62f816adde5312eb97724796efa8e4dff9534f54 (diff) | |
download | CMake-1173cc4ab2dc23a2ac51442273127d2f909f3bc8.zip CMake-1173cc4ab2dc23a2ac51442273127d2f909f3bc8.tar.gz CMake-1173cc4ab2dc23a2ac51442273127d2f909f3bc8.tar.bz2 |
CTest: Update Git submodules with --recursive
Fail if submodules exist and the git version is less than 1.6.5.0.
Inspired-by: Johan Björk <phb@spotify.com>
Diffstat (limited to 'Source/CTest/cmCTestGIT.cxx')
-rw-r--r-- | Source/CTest/cmCTestGIT.cxx | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index aa9e55b..3f55f85 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -24,10 +24,19 @@ #include <ctype.h> //---------------------------------------------------------------------------- +static unsigned int cmCTestGITVersion(unsigned int epic, unsigned int major, + unsigned int minor, unsigned int fix) +{ + // 1.6.5.0 maps to 10605000 + return fix + minor*1000 + major*100000 + epic*10000000; +} + +//---------------------------------------------------------------------------- cmCTestGIT::cmCTestGIT(cmCTest* ct, std::ostream& log): cmCTestGlobalVC(ct, log) { this->PriorRev = this->Unknown; + this->CurrentGitVersion = 0; } //---------------------------------------------------------------------------- @@ -263,7 +272,21 @@ bool cmCTestGIT::UpdateImpl() std::string top_dir = this->FindTopDir(); const char* git = this->CommandLineTool.c_str(); - char const* git_submodule[] = {git, "submodule", "update", 0}; + const char* recursive = "--recursive"; + + // Git < 1.6.5.0 did not support --recursive + if(this->GetGitVersion() < cmCTestGITVersion(1,6,5,0)) + { + recursive = 0; + // No need to require >= 1.6.5.0 if there are no submodules. + if(cmSystemTools::FileExists((top_dir + "/.gitmodules").c_str())) + { + this->Log << "Git >= 1.6.5.0 required for submodule support\n"; + return false; + } + } + + char const* git_submodule[] = {git, "submodule", "update", recursive, 0}; OutputLogger submodule_out(this->Log, "submodule-out> "); OutputLogger submodule_err(this->Log, "submodule-err> "); return this->RunChild(git_submodule, &submodule_out, &submodule_err, @@ -271,6 +294,27 @@ bool cmCTestGIT::UpdateImpl() } //---------------------------------------------------------------------------- +unsigned int cmCTestGIT::GetGitVersion() +{ + if(!this->CurrentGitVersion) + { + const char* git = this->CommandLineTool.c_str(); + char const* git_version[] = {git, "--version", 0}; + std::string version; + OneLineParser version_out(this, "version-out> ", version); + OutputLogger version_err(this->Log, "version-err> "); + unsigned int v[4] = {0,0,0,0}; + if(this->RunChild(git_version, &version_out, &version_err) && + sscanf(version.c_str(), "git version %u.%u.%u.%u", + &v[0], &v[1], &v[2], &v[3]) >= 3) + { + this->CurrentGitVersion = cmCTestGITVersion(v[0], v[1], v[2], v[3]); + } + } + return this->CurrentGitVersion; +} + +//---------------------------------------------------------------------------- /* Diff format: :src-mode dst-mode src-sha1 dst-sha1 status\0 |