ctest_update: Support Git upstream branch rewrites

Use 'git fetch' followed by 'git reset' to update the source tree.  This
is better than 'git pull' because it can handle a rewritten upstream
branch and does not leave local modifications.  After fetch, parse
FETCH_HEAD to find the merge head that 'git pull' would choose to track
the upstream branch.  Then reset to the selected head.

In the normal fast-forward case the behavior remains unchanged.
However, now local modifications and commits will be erased, and
upstream rewrites are handled smoothly.  This ensures that the upstream
branch is tested as expected.
This commit is contained in:
Brad King 2010-06-08 16:37:04 -04:00
parent 2eae651acc
commit c3781efb28
6 changed files with 50 additions and 16 deletions

View File

@ -15,6 +15,7 @@ Changes since CMake 2.8.1
- CTest: Report failure in Update.xml - CTest: Report failure in Update.xml
- CTest: Submit author email in Update.xml - CTest: Submit author email in Update.xml
- CTest: Teach ctest_update about Git submodules - CTest: Teach ctest_update about Git submodules
- CTest: Teach ctest_update to handle Git upstream branch rewrites
- Cygwin: Export all symbols with ENABLE_EXPORTS (#10122) - Cygwin: Export all symbols with ENABLE_EXPORTS (#10122)
- Do not list file names during 'cmake -E tar xz' - Do not list file names during 'cmake -E tar xz'
- Documentation: Comply with "XHTML 1.0 Strict" - Documentation: Comply with "XHTML 1.0 Strict"

View File

@ -85,16 +85,14 @@ void cmCTestGIT::NoteNewRevision()
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmCTestGIT::UpdateByPull() bool cmCTestGIT::UpdateByFetchAndReset()
{ {
const char* git = this->CommandLineTool.c_str(); const char* git = this->CommandLineTool.c_str();
// Use "git pull" to update the working tree. // Use "git fetch" to get remote commits.
std::vector<char const*> git_pull; std::vector<char const*> git_fetch;
git_pull.push_back(git); git_fetch.push_back(git);
git_pull.push_back("pull"); git_fetch.push_back("fetch");
// TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
// Add user-specified update options. // Add user-specified update options.
std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions"); std::string opts = this->CTest->GetCTestConfiguration("UpdateOptions");
@ -106,15 +104,44 @@ bool cmCTestGIT::UpdateByPull()
for(std::vector<cmStdString>::const_iterator ai = args.begin(); for(std::vector<cmStdString>::const_iterator ai = args.begin();
ai != args.end(); ++ai) ai != args.end(); ++ai)
{ {
git_pull.push_back(ai->c_str()); git_fetch.push_back(ai->c_str());
} }
// Sentinel argument. // Sentinel argument.
git_pull.push_back(0); git_fetch.push_back(0);
OutputLogger out(this->Log, "pull-out> "); // Fetch upstream refs.
OutputLogger err(this->Log, "pull-err> "); OutputLogger fetch_out(this->Log, "fetch-out> ");
return this->RunUpdateCommand(&git_pull[0], &out, &err); 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);
}
}
}
}
// 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);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -143,7 +170,7 @@ bool cmCTestGIT::UpdateInternal()
{ {
return this->UpdateByCustom(custom); return this->UpdateByCustom(custom);
} }
return this->UpdateByPull(); return this->UpdateByFetchAndReset();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -32,7 +32,7 @@ private:
virtual void NoteNewRevision(); virtual void NoteNewRevision();
virtual bool UpdateImpl(); virtual bool UpdateImpl();
bool UpdateByPull(); bool UpdateByFetchAndReset();
bool UpdateByCustom(std::string const& custom); bool UpdateByCustom(std::string const& custom);
bool UpdateInternal(); bool UpdateInternal();

View File

@ -191,13 +191,17 @@ function(run_dashboard_command_line bin_dir)
# Verify the updates reported by CTest. # Verify the updates reported by CTest.
list(APPEND UPDATE_MAYBE Updated{subdir}) list(APPEND UPDATE_MAYBE Updated{subdir})
set(_modified Modified{CTestConfig.cmake})
if(UPDATE_NO_MODIFIED)
set(_modified "")
endif()
check_updates(${bin_dir} check_updates(${bin_dir}
Updated{foo.txt} Updated{foo.txt}
Updated{bar.txt} Updated{bar.txt}
Updated{zot.txt} Updated{zot.txt}
Updated{subdir/foo.txt} Updated{subdir/foo.txt}
Updated{subdir/bar.txt} Updated{subdir/bar.txt}
Modified{CTestConfig.cmake} ${_modified}
) )
endfunction(run_dashboard_command_line) endfunction(run_dashboard_command_line)

View File

@ -227,7 +227,9 @@ UpdateCommand: ${GIT}
") ")
# Run the dashboard command line interface. # Run the dashboard command line interface.
set(UPDATE_NO_MODIFIED 1)
run_dashboard_command_line(user-binary) run_dashboard_command_line(user-binary)
set(UPDATE_NO_MODIFIED 0)
rewind_source(user-source) rewind_source(user-source)
modify_content(user-source) modify_content(user-source)

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
if test "x$1" = "xpull"; then if test "x$1" = "xpull" -o "x$1" = "xreset"; then
"@GIT@" "$@" && sleep 1 && touch foo.txt "@GIT@" "$@" && sleep 1 && touch foo.txt
else else
exec "@GIT@" "$@" exec "@GIT@" "$@"