CTestUpdateGIT.cmake.in 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # This script drives creation of a git repository and checks
  2. # that CTest can update from it.
  3. #-----------------------------------------------------------------------------
  4. # Test in a directory next to this script.
  5. get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
  6. set(TOP "${TOP}/@CTestUpdateGIT_DIR@")
  7. # Include code common to all update tests.
  8. include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
  9. #-----------------------------------------------------------------------------
  10. # Report git tools in use.
  11. message("Using GIT tools:")
  12. set(GIT "@GIT_EXECUTABLE@")
  13. message(" git = ${GIT}")
  14. set(AUTHOR_CONFIG "[user]
  15. \tname = Test Author
  16. \temail = [email protected]
  17. ")
  18. #-----------------------------------------------------------------------------
  19. # Initialize the testing directory.
  20. message("Creating test directory...")
  21. init_testing()
  22. #-----------------------------------------------------------------------------
  23. # Create the repository.
  24. message("Creating repository...")
  25. file(MAKE_DIRECTORY ${TOP}/repo.git)
  26. run_child(
  27. WORKING_DIRECTORY ${TOP}/repo.git
  28. COMMAND ${GIT} init --bare
  29. )
  30. file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
  31. set(REPO file://${TOP}/repo.git)
  32. #-----------------------------------------------------------------------------
  33. # Import initial content into the repository.
  34. message("Importing content...")
  35. create_content(import)
  36. # Import the content into the repository.
  37. run_child(WORKING_DIRECTORY ${TOP}/import
  38. COMMAND ${GIT} init
  39. )
  40. file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
  41. file(APPEND ${TOP}/import/.git/config "
  42. [remote \"origin\"]
  43. \turl = ${REPO}
  44. \tfetch = +refs/heads/*:refs/remotes/origin/*
  45. ${AUTHOR_CONFIG}")
  46. run_child(WORKING_DIRECTORY ${TOP}/import
  47. COMMAND ${GIT} add .
  48. )
  49. run_child(WORKING_DIRECTORY ${TOP}/import
  50. COMMAND ${GIT} commit -m "Initial content"
  51. )
  52. run_child(WORKING_DIRECTORY ${TOP}/import
  53. COMMAND ${GIT} push origin master:refs/heads/master
  54. )
  55. #-----------------------------------------------------------------------------
  56. # Create a working tree.
  57. message("Checking out revision 1...")
  58. run_child(
  59. WORKING_DIRECTORY ${TOP}
  60. COMMAND ${GIT} clone ${REPO} user-source
  61. )
  62. file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
  63. file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
  64. #-----------------------------------------------------------------------------
  65. # Make changes in the working tree.
  66. message("Changing content...")
  67. update_content(user-source files_added files_removed dirs_added)
  68. if(dirs_added)
  69. run_child(
  70. WORKING_DIRECTORY ${TOP}/user-source
  71. COMMAND ${GIT} add ${dirs_added}
  72. )
  73. endif(dirs_added)
  74. run_child(
  75. WORKING_DIRECTORY ${TOP}/user-source
  76. COMMAND ${GIT} add ${files_added}
  77. )
  78. run_child(
  79. WORKING_DIRECTORY ${TOP}/user-source
  80. COMMAND ${GIT} rm ${files_removed}
  81. )
  82. run_child(
  83. WORKING_DIRECTORY ${TOP}/user-source
  84. COMMAND ${GIT} add -u
  85. )
  86. #-----------------------------------------------------------------------------
  87. # Commit the changes to the repository.
  88. message("Committing revision 2...")
  89. run_child(
  90. WORKING_DIRECTORY ${TOP}/user-source
  91. COMMAND ${GIT} commit -m "Changed content"
  92. )
  93. run_child(
  94. WORKING_DIRECTORY ${TOP}/user-source
  95. COMMAND ${GIT} push origin
  96. )
  97. #-----------------------------------------------------------------------------
  98. # Make changes in the working tree.
  99. message("Changing content again...")
  100. change_content(user-source)
  101. run_child(
  102. WORKING_DIRECTORY ${TOP}/user-source
  103. COMMAND ${GIT} add -u
  104. )
  105. #-----------------------------------------------------------------------------
  106. # Commit the changes to the repository.
  107. message("Committing revision 3...")
  108. run_child(
  109. WORKING_DIRECTORY ${TOP}/user-source
  110. COMMAND ${GIT} commit -m "Changed content again"
  111. )
  112. run_child(
  113. WORKING_DIRECTORY ${TOP}/user-source
  114. COMMAND ${GIT} push origin
  115. )
  116. #-----------------------------------------------------------------------------
  117. # Go back to before the changes so we can test updating.
  118. message("Backing up to revision 1...")
  119. run_child(
  120. WORKING_DIRECTORY ${TOP}/user-source
  121. COMMAND ${GIT} reset --hard master~2
  122. )
  123. # Create a modified file.
  124. modify_content(user-source)
  125. #-----------------------------------------------------------------------------
  126. # Test updating the user work directory with the command-line interface.
  127. message("Running CTest Dashboard Command Line...")
  128. # Create the user build tree.
  129. create_build_tree(user-source user-binary)
  130. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  131. "# GIT command configuration
  132. UpdateCommand: ${GIT}
  133. ")
  134. # Run the dashboard command line interface.
  135. run_dashboard_command_line(user-binary)
  136. #-----------------------------------------------------------------------------
  137. # Test initial checkout and update with a dashboard script.
  138. message("Running CTest Dashboard Script...")
  139. create_dashboard_script(dashboard.cmake
  140. "# git command configuration
  141. set(CTEST_GIT_COMMAND \"${GIT}\")
  142. set(CTEST_GIT_UPDATE_OPTIONS)
  143. execute_process(
  144. WORKING_DIRECTORY \"${TOP}\"
  145. COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
  146. )
  147. execute_process(
  148. WORKING_DIRECTORY \"${TOP}/dash-source\"
  149. COMMAND \"${GIT}\" reset --hard master~2
  150. )
  151. ")
  152. # Run the dashboard script with CTest.
  153. run_dashboard_script(dashboard.cmake)