From 1173cc4ab2dc23a2ac51442273127d2f909f3bc8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Feb 2011 15:47:50 -0500 Subject: [PATCH 1/2] CTest: Update Git submodules with --recursive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fail if submodules exist and the git version is less than 1.6.5.0. Inspired-by: Johan Björk --- Source/CTest/cmCTestGIT.cxx | 46 ++++++++++++++++++++++++++++++++++++- Source/CTest/cmCTestGIT.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index aa9e55b23..3f55f85bf 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -23,11 +23,20 @@ #include #include +//---------------------------------------------------------------------------- +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,13 +272,48 @@ 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, top_dir.c_str()); } +//---------------------------------------------------------------------------- +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: diff --git a/Source/CTest/cmCTestGIT.h b/Source/CTest/cmCTestGIT.h index 1765340d5..f4fae8f9d 100644 --- a/Source/CTest/cmCTestGIT.h +++ b/Source/CTest/cmCTestGIT.h @@ -27,6 +27,8 @@ public: virtual ~cmCTestGIT(); private: + unsigned int CurrentGitVersion; + unsigned int GetGitVersion(); std::string GetWorkingRevision(); virtual void NoteOldRevision(); virtual void NoteNewRevision(); From 732af7fbba47d1f88fdaed6b9fac520e8e06313c Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Mar 2011 13:57:30 -0500 Subject: [PATCH 2/2] CTest: Do not fail with submodules and Git < 1.6.5.0 Several major Linux distributions still do not provide Git >= 1.6.5.0 in their stable package lists. Prior to commit 1173cc4a (Update Git submodules with --recursive, 2011-02-22) CTest was able to use older Git versions but simply silently failed to update submodules recursively. Instead of failing with older Git versions preserve the status quo and add a warning in the update log. Users testing projects with recursive submodules may simply update to a Git new enough to support them. --- Source/CTest/cmCTestGIT.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 3f55f85bf..2c1a0afd9 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -281,8 +281,7 @@ bool cmCTestGIT::UpdateImpl() // 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; + this->Log << "Git < 1.6.5.0 cannot update submodules recursively\n"; } }