CTestUpdateGIT.cmake.in 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if(UNIX)
  23. set(src "@CMAKE_CURRENT_SOURCE_DIR@")
  24. configure_file(${src}/CTestUpdateGIT.sh.in ${TOP}/git.sh @ONLY)
  25. set(GIT ${TOP}/git.sh)
  26. endif()
  27. #-----------------------------------------------------------------------------
  28. # Create the repository.
  29. message("Creating repository...")
  30. file(MAKE_DIRECTORY ${TOP}/repo.git)
  31. run_child(
  32. WORKING_DIRECTORY ${TOP}/repo.git
  33. COMMAND ${GIT} --bare init
  34. )
  35. file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
  36. set(REPO file://${TOP}/repo.git)
  37. #-----------------------------------------------------------------------------
  38. # Import initial content into the repository.
  39. message("Importing content...")
  40. create_content(import)
  41. # Import the content into the repository.
  42. run_child(WORKING_DIRECTORY ${TOP}/import
  43. COMMAND ${GIT} init
  44. )
  45. file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
  46. file(APPEND ${TOP}/import/.git/config "
  47. [remote \"origin\"]
  48. \turl = ${REPO}
  49. \tfetch = +refs/heads/*:refs/remotes/origin/*
  50. ${AUTHOR_CONFIG}")
  51. run_child(WORKING_DIRECTORY ${TOP}/import
  52. COMMAND ${GIT} add .
  53. )
  54. run_child(WORKING_DIRECTORY ${TOP}/import
  55. COMMAND ${GIT} commit -m "Initial content"
  56. )
  57. run_child(WORKING_DIRECTORY ${TOP}/import
  58. COMMAND ${GIT} push origin master:refs/heads/master
  59. )
  60. #-----------------------------------------------------------------------------
  61. # Create a working tree.
  62. message("Checking out revision 1...")
  63. run_child(
  64. WORKING_DIRECTORY ${TOP}
  65. COMMAND ${GIT} clone ${REPO} user-source
  66. )
  67. file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
  68. file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
  69. #-----------------------------------------------------------------------------
  70. # Make changes in the working tree.
  71. message("Changing content...")
  72. update_content(user-source files_added files_removed dirs_added)
  73. if(dirs_added)
  74. run_child(
  75. WORKING_DIRECTORY ${TOP}/user-source
  76. COMMAND ${GIT} add ${dirs_added}
  77. )
  78. endif(dirs_added)
  79. run_child(
  80. WORKING_DIRECTORY ${TOP}/user-source
  81. COMMAND ${GIT} add ${files_added}
  82. )
  83. run_child(
  84. WORKING_DIRECTORY ${TOP}/user-source
  85. COMMAND ${GIT} rm ${files_removed}
  86. )
  87. run_child(
  88. WORKING_DIRECTORY ${TOP}/user-source
  89. COMMAND ${GIT} add -u
  90. )
  91. #-----------------------------------------------------------------------------
  92. # Commit the changes to the repository.
  93. message("Committing revision 2...")
  94. run_child(
  95. WORKING_DIRECTORY ${TOP}/user-source
  96. COMMAND ${GIT} commit -m "Changed content"
  97. )
  98. run_child(
  99. WORKING_DIRECTORY ${TOP}/user-source
  100. COMMAND ${GIT} push origin
  101. )
  102. #-----------------------------------------------------------------------------
  103. # Make changes in the working tree.
  104. message("Changing content again...")
  105. change_content(user-source)
  106. run_child(
  107. WORKING_DIRECTORY ${TOP}/user-source
  108. COMMAND ${GIT} add -u
  109. )
  110. #-----------------------------------------------------------------------------
  111. # Commit the changes to the repository.
  112. message("Committing revision 3...")
  113. run_child(
  114. WORKING_DIRECTORY ${TOP}/user-source
  115. COMMAND ${GIT} commit -m "Changed content again"
  116. )
  117. run_child(
  118. WORKING_DIRECTORY ${TOP}/user-source
  119. COMMAND ${GIT} push origin
  120. )
  121. #-----------------------------------------------------------------------------
  122. # Go back to before the changes so we can test updating.
  123. message("Backing up to revision 1...")
  124. run_child(
  125. WORKING_DIRECTORY ${TOP}/user-source
  126. COMMAND ${GIT} reset --hard master~2
  127. )
  128. # Make sure pull does not try to rebase (which does not work with
  129. # modified files) even if ~/.gitconfig sets "branch.master.rebase".
  130. run_child(
  131. WORKING_DIRECTORY ${TOP}/user-source
  132. COMMAND ${GIT} config branch.master.rebase false
  133. )
  134. # Create a modified file.
  135. modify_content(user-source)
  136. #-----------------------------------------------------------------------------
  137. # Test updating the user work directory with the command-line interface.
  138. message("Running CTest Dashboard Command Line...")
  139. # Create the user build tree.
  140. create_build_tree(user-source user-binary)
  141. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  142. "# GIT command configuration
  143. UpdateCommand: ${GIT}
  144. ")
  145. # Run the dashboard command line interface.
  146. run_dashboard_command_line(user-binary)
  147. #-----------------------------------------------------------------------------
  148. # Test initial checkout and update with a dashboard script.
  149. message("Running CTest Dashboard Script...")
  150. create_dashboard_script(dashboard.cmake
  151. "# git command configuration
  152. set(CTEST_GIT_COMMAND \"${GIT}\")
  153. set(CTEST_GIT_UPDATE_OPTIONS)
  154. execute_process(
  155. WORKING_DIRECTORY \"${TOP}\"
  156. COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
  157. )
  158. execute_process(
  159. WORKING_DIRECTORY \"${TOP}/dash-source\"
  160. COMMAND \"${GIT}\" reset --hard master~2
  161. )
  162. ")
  163. # Run the dashboard script with CTest.
  164. run_dashboard_script(dashboard.cmake)