diff options
author | Brad King <brad.king@kitware.com> | 2010-06-15 18:10:41 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2010-06-15 18:10:41 (GMT) |
commit | b4aa834900f30fb7a2dc1148ba9e947a5bd98ee1 (patch) | |
tree | 27a91488ee0459b769a11ea4bc348f2b377d558e /Source | |
parent | a8a10d0f6a6f19170f38a91e51a283af885fb79b (diff) | |
parent | c3781efb28a35f54ed6306354330734994f2c8b1 (diff) | |
download | CMake-b4aa834900f30fb7a2dc1148ba9e947a5bd98ee1.zip CMake-b4aa834900f30fb7a2dc1148ba9e947a5bd98ee1.tar.gz CMake-b4aa834900f30fb7a2dc1148ba9e947a5bd98ee1.tar.bz2 |
Merge branch 'ctest-git-flexibility'
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CTest/cmCTestGIT.cxx | 98 | ||||
-rw-r--r-- | Source/CTest/cmCTestGIT.h | 4 | ||||
-rw-r--r-- | Source/CTest/cmCTestUpdateCommand.cxx | 2 |
3 files changed, 87 insertions, 17 deletions
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index f5ba361..6c3631c 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -85,16 +85,14 @@ void cmCTestGIT::NoteNewRevision() } //---------------------------------------------------------------------------- -bool cmCTestGIT::UpdateImpl() +bool cmCTestGIT::UpdateByFetchAndReset() { const char* git = this->CommandLineTool.c_str(); - // Use "git pull" to update the working tree. - std::vector<char const*> git_pull; - git_pull.push_back(git); - git_pull.push_back("pull"); - - // TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY) + // Use "git fetch" to get remote commits. + std::vector<char const*> git_fetch; + git_fetch.push_back(git); + git_fetch.push_back("fetch"); // Add user-specified update options. std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions"); @@ -106,22 +104,88 @@ bool cmCTestGIT::UpdateImpl() for(std::vector<cmStdString>::const_iterator ai = args.begin(); ai != args.end(); ++ai) { - git_pull.push_back(ai->c_str()); + git_fetch.push_back(ai->c_str()); } // Sentinel argument. - git_pull.push_back(0); + git_fetch.push_back(0); + + // Fetch upstream refs. + OutputLogger fetch_out(this->Log, "fetch-out> "); + OutputLogger fetch_err(this->Log, "fetch-err> "); + if(!this->RunUpdateCommand(&git_fetch[0], &fetch_out, &fetch_err)) + { + return false; + } + + // Identify the merge head that would be used by "git pull". + std::string sha1; + { + std::string fetch_head = this->SourceDirectory + "/.git/FETCH_HEAD"; + std::ifstream fin(fetch_head.c_str(), std::ios::in | std::ios::binary); + std::string line; + while(sha1.empty() && cmSystemTools::GetLineFromStream(fin, line)) + { + if(line.find("\tnot-for-merge\t") == line.npos) + { + std::string::size_type pos = line.find('\t'); + if(pos != line.npos) + { + sha1 = line.substr(0, pos); + } + } + } + } - OutputLogger out(this->Log, "pull-out> "); - OutputLogger err(this->Log, "pull-err> "); - if(this->RunUpdateCommand(&git_pull[0], &out, &err)) + // Reset the local branch to point at that tracked from upstream. + char const* git_reset[] = {git, "reset", "--hard", sha1.c_str(), 0}; + OutputLogger reset_out(this->Log, "reset-out> "); + OutputLogger reset_err(this->Log, "reset-err> "); + return this->RunChild(&git_reset[0], &reset_out, &reset_err); +} + +//---------------------------------------------------------------------------- +bool cmCTestGIT::UpdateByCustom(std::string const& custom) +{ + std::vector<std::string> git_custom_command; + cmSystemTools::ExpandListArgument(custom, git_custom_command, true); + std::vector<char const*> git_custom; + for(std::vector<std::string>::const_iterator + i = git_custom_command.begin(); i != git_custom_command.end(); ++i) { - char const* git_submodule[] = {git, "submodule", "update", 0}; - OutputLogger out2(this->Log, "submodule-out> "); - OutputLogger err2(this->Log, "submodule-err> "); - return this->RunChild(git_submodule, &out2, &err2); + git_custom.push_back(i->c_str()); } - return false; + git_custom.push_back(0); + + OutputLogger custom_out(this->Log, "custom-out> "); + OutputLogger custom_err(this->Log, "custom-err> "); + return this->RunUpdateCommand(&git_custom[0], &custom_out, &custom_err); +} + +//---------------------------------------------------------------------------- +bool cmCTestGIT::UpdateInternal() +{ + std::string custom = this->CTest->GetCTestConfiguration("GITUpdateCustom"); + if(!custom.empty()) + { + return this->UpdateByCustom(custom); + } + return this->UpdateByFetchAndReset(); +} + +//---------------------------------------------------------------------------- +bool cmCTestGIT::UpdateImpl() +{ + if(!this->UpdateInternal()) + { + return false; + } + + const char* git = this->CommandLineTool.c_str(); + char const* git_submodule[] = {git, "submodule", "update", 0}; + OutputLogger submodule_out(this->Log, "submodule-out> "); + OutputLogger submodule_err(this->Log, "submodule-err> "); + return this->RunChild(git_submodule, &submodule_out, &submodule_err); } //---------------------------------------------------------------------------- diff --git a/Source/CTest/cmCTestGIT.h b/Source/CTest/cmCTestGIT.h index 0b6ad2e..d8681fe 100644 --- a/Source/CTest/cmCTestGIT.h +++ b/Source/CTest/cmCTestGIT.h @@ -32,6 +32,10 @@ private: virtual void NoteNewRevision(); virtual bool UpdateImpl(); + bool UpdateByFetchAndReset(); + bool UpdateByCustom(std::string const& custom); + bool UpdateInternal(); + void LoadRevisions(); void LoadModifications(); diff --git a/Source/CTest/cmCTestUpdateCommand.cxx b/Source/CTest/cmCTestUpdateCommand.cxx index 571745d..8414349 100644 --- a/Source/CTest/cmCTestUpdateCommand.cxx +++ b/Source/CTest/cmCTestUpdateCommand.cxx @@ -52,6 +52,8 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler() this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile, "GITUpdateOptions", "CTEST_GIT_UPDATE_OPTIONS"); this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile, + "GITUpdateCustom", "CTEST_GIT_UPDATE_CUSTOM"); + this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile, "HGCommand", "CTEST_HG_COMMAND"); this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile, "HGUpdateOptions", "CTEST_HG_UPDATE_OPTIONS"); |