Commit 9c17cbeb authored by Brad King's avatar Brad King

ENH: Teach CTest to handle git repositories

This creates cmCTestGIT to drive CTest Update handling on git-based work
trees.  Currently we always update to the head of the remote tracking
branch (git pull), so the nightly start time is ignored for Nightly
builds.  A later change will address this.  See issue #6994.
parent d25289ad
......@@ -361,6 +361,8 @@ SET(CTEST_SRCS cmCTest.cxx
CTest/cmCTestCVS.h
CTest/cmCTestSVN.cxx
CTest/cmCTestSVN.h
CTest/cmCTestGIT.cxx
CTest/cmCTestGIT.h
)
# Build CTestLib
......
This diff is collapsed.
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCTestGIT_h
#define cmCTestGIT_h
#include "cmCTestGlobalVC.h"
/** \class cmCTestGIT
* \brief Interaction with git command-line tool
*
*/
class cmCTestGIT: public cmCTestGlobalVC
{
public:
/** Construct with a CTest instance and update log stream. */
cmCTestGIT(cmCTest* ctest, std::ostream& log);
virtual ~cmCTestGIT();
private:
std::string GetWorkingRevision();
virtual void NoteOldRevision();
virtual void NoteNewRevision();
virtual bool UpdateImpl();
void LoadRevisions();
void LoadModifications();
// Parsing helper classes.
class OneLineParser;
class DiffParser;
class CommitParser;
friend class OneLineParser;
friend class DiffParser;
friend class CommitParser;
};
#endif
......@@ -48,6 +48,10 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
"SVNCommand", "CTEST_SVN_COMMAND");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"SVNUpdateOptions", "CTEST_SVN_UPDATE_OPTIONS");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"GITCommand", "CTEST_GIT_COMMAND");
this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
"GITUpdateOptions", "CTEST_GIT_UPDATE_OPTIONS");
const char* initialCheckoutCommand
= this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
......
......@@ -30,6 +30,7 @@
#include "cmCTestVC.h"
#include "cmCTestCVS.h"
#include "cmCTestSVN.h"
#include "cmCTestGIT.h"
#include <cmsys/auto_ptr.hxx>
......@@ -50,7 +51,8 @@ static const char* cmCTestUpdateHandlerUpdateStrings[] =
{
"Unknown",
"CVS",
"SVN"
"SVN",
"GIT"
};
static const char* cmCTestUpdateHandlerUpdateToString(int type)
......@@ -133,6 +135,10 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
{
return cmCTestUpdateHandler::e_SVN;
}
if ( stype.find("git") != std::string::npos )
{
return cmCTestUpdateHandler::e_GIT;
}
}
else
{
......@@ -147,6 +153,10 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
{
return cmCTestUpdateHandler::e_SVN;
}
if ( stype.find("git") != std::string::npos )
{
return cmCTestUpdateHandler::e_GIT;
}
}
return cmCTestUpdateHandler::e_UNKNOWN;
}
......@@ -204,6 +214,7 @@ int cmCTestUpdateHandler::ProcessHandler()
{
case e_CVS: vc.reset(new cmCTestCVS(this->CTest, ofs)); break;
case e_SVN: vc.reset(new cmCTestSVN(this->CTest, ofs)); break;
case e_GIT: vc.reset(new cmCTestGIT(this->CTest, ofs)); break;
default: vc.reset(new cmCTestVC(this->CTest, ofs)); break;
}
vc->SetCommandLineTool(this->UpdateCommand);
......@@ -337,6 +348,12 @@ int cmCTestUpdateHandler::DetectVCS(const char* dir)
{
return cmCTestUpdateHandler::e_CVS;
}
sourceDirectory = dir;
sourceDirectory += "/.git";
if ( cmSystemTools::FileExists(sourceDirectory.c_str()) )
{
return cmCTestUpdateHandler::e_GIT;
}
return cmCTestUpdateHandler::e_UNKNOWN;
}
......@@ -364,6 +381,7 @@ bool cmCTestUpdateHandler::SelectVCS()
{
case e_CVS: key = "CVSCommand"; break;
case e_SVN: key = "SVNCommand"; break;
case e_GIT: key = "GITCommand"; break;
default: break;
}
if (key)
......
......@@ -46,6 +46,7 @@ public:
e_UNKNOWN = 0,
e_CVS,
e_SVN,
e_GIT,
e_LAST
};
......
......@@ -925,6 +925,19 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateCVS_DIR}")
ENDIF(CTEST_TEST_UPDATE_CVS AND CVS_FOUND)
# Test CTest Update with GIT
FIND_PROGRAM(GIT_EXECUTABLE NAMES git)
MARK_AS_ADVANCED(GIT_EXECUTABLE)
IF(GIT_EXECUTABLE)
SET(CTestUpdateGIT_DIR "CTest UpdateGIT")
CONFIGURE_FILE("${CMake_SOURCE_DIR}/Tests/CTestUpdateGIT.cmake.in"
"${CMake_BINARY_DIR}/Tests/CTestUpdateGIT.cmake" @ONLY)
ADD_TEST(CTest.UpdateGIT ${CMAKE_CMAKE_COMMAND}
-P "${CMake_BINARY_DIR}/Tests/CTestUpdateGIT.cmake"
)
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${CTestUpdateGIT_DIR}")
ENDIF(GIT_EXECUTABLE)
ENDIF(CTEST_TEST_UPDATE)
IF (CTEST_TEST_CTEST AND CMAKE_RUN_LONG_TESTS)
......
# This script drives creation of a git repository and checks
# that CTest can update from it.
#-----------------------------------------------------------------------------
# Test in a directory next to this script.
get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(TOP "${TOP}/@CTestUpdateGIT_DIR@")
# Include code common to all update tests.
include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
#-----------------------------------------------------------------------------
# Report git tools in use.
message("Using GIT tools:")
set(GIT "@GIT_EXECUTABLE@")
message(" git = ${GIT}")
set(AUTHOR_CONFIG "[user]
\tname = Test Author
\temail = testauthor@cmake.org
")
#-----------------------------------------------------------------------------
# Initialize the testing directory.
message("Creating test directory...")
init_testing()
#-----------------------------------------------------------------------------
# Create the repository.
message("Creating repository...")
file(MAKE_DIRECTORY ${TOP}/repo.git)
run_child(
WORKING_DIRECTORY ${TOP}/repo.git
COMMAND ${GIT} init --bare
)
file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
set(REPO file://${TOP}/repo.git)
#-----------------------------------------------------------------------------
# Import initial content into the repository.
message("Importing content...")
create_content(import)
# Import the content into the repository.
run_child(WORKING_DIRECTORY ${TOP}/import
COMMAND ${GIT} init
)
file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
file(APPEND ${TOP}/import/.git/config "
[remote \"origin\"]
\turl = ${REPO}
\tfetch = +refs/heads/*:refs/remotes/origin/*
${AUTHOR_CONFIG}")
run_child(WORKING_DIRECTORY ${TOP}/import
COMMAND ${GIT} add .
)
run_child(WORKING_DIRECTORY ${TOP}/import
COMMAND ${GIT} commit -m "Initial content"
)
run_child(WORKING_DIRECTORY ${TOP}/import
COMMAND ${GIT} push origin master:refs/heads/master
)
#-----------------------------------------------------------------------------
# Create a working tree.
message("Checking out revision 1...")
run_child(
WORKING_DIRECTORY ${TOP}
COMMAND ${GIT} clone ${REPO} user-source
)
file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
#-----------------------------------------------------------------------------
# Make changes in the working tree.
message("Changing content...")
update_content(user-source files_added files_removed dirs_added)
if(dirs_added)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} add ${dirs_added}
)
endif(dirs_added)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} add ${files_added}
)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} rm ${files_removed}
)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} add -u
)
#-----------------------------------------------------------------------------
# Commit the changes to the repository.
message("Committing revision 2...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} commit -m "Changed content"
)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} push origin
)
#-----------------------------------------------------------------------------
# Make changes in the working tree.
message("Changing content again...")
change_content(user-source)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} add -u
)
#-----------------------------------------------------------------------------
# Commit the changes to the repository.
message("Committing revision 3...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} commit -m "Changed content again"
)
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} push origin
)
#-----------------------------------------------------------------------------
# Go back to before the changes so we can test updating.
message("Backing up to revision 1...")
run_child(
WORKING_DIRECTORY ${TOP}/user-source
COMMAND ${GIT} reset --hard master~2
)
# Create a modified file.
modify_content(user-source)
#-----------------------------------------------------------------------------
# Test updating the user work directory with the command-line interface.
message("Running CTest Dashboard Command Line...")
# Create the user build tree.
create_build_tree(user-source user-binary)
file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
"# GIT command configuration
UpdateCommand: ${GIT}
")
# Run the dashboard command line interface.
run_dashboard_command_line(user-binary)
#-----------------------------------------------------------------------------
# Test initial checkout and update with a dashboard script.
message("Running CTest Dashboard Script...")
create_dashboard_script(dashboard.cmake
"# git command configuration
set(CTEST_GIT_COMMAND \"${GIT}\")
set(CTEST_GIT_UPDATE_OPTIONS)
execute_process(
WORKING_DIRECTORY \"${TOP}\"
COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
)
execute_process(
WORKING_DIRECTORY \"${TOP}/dash-source\"
COMMAND \"${GIT}\" reset --hard master~2
)
")
# Run the dashboard script with CTest.
run_dashboard_script(dashboard.cmake)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment