CTestUpdateGIT.cmake.in 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. set(UPDATE_EXTRA Updated{module})
  8. # Include code common to all update tests.
  9. include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
  10. #-----------------------------------------------------------------------------
  11. # Report git tools in use.
  12. message("Using GIT tools:")
  13. set(GIT "@GIT_EXECUTABLE@")
  14. message(" git = ${GIT}")
  15. set(AUTHOR_CONFIG "[user]
  16. \tname = Test Author
  17. \temail = [email protected]
  18. ")
  19. #-----------------------------------------------------------------------------
  20. # Initialize the testing directory.
  21. message("Creating test directory...")
  22. init_testing()
  23. if(UNIX)
  24. set(src "@CMAKE_CURRENT_SOURCE_DIR@")
  25. configure_file(${src}/CTestUpdateGIT.sh.in ${TOP}/git.sh @ONLY)
  26. set(GIT ${TOP}/git.sh)
  27. endif()
  28. #-----------------------------------------------------------------------------
  29. # Create the repository.
  30. message("Creating repository...")
  31. file(MAKE_DIRECTORY ${TOP}/repo.git)
  32. run_child(
  33. WORKING_DIRECTORY ${TOP}/repo.git
  34. COMMAND ${GIT} --bare init
  35. )
  36. file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
  37. set(REPO file://${TOP}/repo.git)
  38. # Create submodule repository.
  39. message("Creating submodule...")
  40. file(MAKE_DIRECTORY ${TOP}/module.git)
  41. run_child(
  42. WORKING_DIRECTORY ${TOP}/module.git
  43. COMMAND ${GIT} --bare init
  44. )
  45. file(REMOVE_RECURSE ${TOP}/module.git/hooks)
  46. set(MOD_REPO file://${TOP}/module.git)
  47. create_content(module)
  48. run_child(WORKING_DIRECTORY ${TOP}/module
  49. COMMAND ${GIT} init
  50. )
  51. file(REMOVE_RECURSE ${TOP}/module/.git/hooks)
  52. file(APPEND ${TOP}/module/.git/config "
  53. [remote \"origin\"]
  54. \turl = ${MOD_REPO}
  55. \tfetch = +refs/heads/*:refs/remotes/origin/*
  56. ${AUTHOR_CONFIG}")
  57. run_child(WORKING_DIRECTORY ${TOP}/module
  58. COMMAND ${GIT} add .
  59. )
  60. run_child(WORKING_DIRECTORY ${TOP}/module
  61. COMMAND ${GIT} commit -m "Initial content"
  62. )
  63. run_child(WORKING_DIRECTORY ${TOP}/module
  64. COMMAND ${GIT} push origin master:refs/heads/master
  65. )
  66. #-----------------------------------------------------------------------------
  67. # Import initial content into the repository.
  68. message("Importing content...")
  69. create_content(import)
  70. # Import the content into the repository.
  71. run_child(WORKING_DIRECTORY ${TOP}/import
  72. COMMAND ${GIT} init
  73. )
  74. file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
  75. file(APPEND ${TOP}/import/.git/config "
  76. [remote \"origin\"]
  77. \turl = ${REPO}
  78. \tfetch = +refs/heads/*:refs/remotes/origin/*
  79. ${AUTHOR_CONFIG}")
  80. run_child(WORKING_DIRECTORY ${TOP}/import
  81. COMMAND ${GIT} add .
  82. )
  83. run_child(WORKING_DIRECTORY ${TOP}/import
  84. COMMAND ${GIT} config core.safecrlf false
  85. )
  86. run_child(WORKING_DIRECTORY ${TOP}/import
  87. COMMAND ${GIT} submodule add ${MOD_REPO} module
  88. )
  89. run_child(WORKING_DIRECTORY ${TOP}/import
  90. COMMAND ${GIT} commit -m "Initial content"
  91. )
  92. run_child(WORKING_DIRECTORY ${TOP}/import
  93. COMMAND ${GIT} push origin master:refs/heads/master
  94. )
  95. #-----------------------------------------------------------------------------
  96. # Modify the submodule.
  97. change_content(module)
  98. run_child(WORKING_DIRECTORY ${TOP}/module
  99. COMMAND ${GIT} add -u
  100. )
  101. run_child(WORKING_DIRECTORY ${TOP}/module
  102. COMMAND ${GIT} commit -m "Changed content"
  103. )
  104. run_child(WORKING_DIRECTORY ${TOP}/module
  105. COMMAND ${GIT} push origin master:refs/heads/master
  106. )
  107. #-----------------------------------------------------------------------------
  108. # Create a working tree.
  109. message("Checking out revision 1...")
  110. run_child(
  111. WORKING_DIRECTORY ${TOP}
  112. COMMAND ${GIT} clone ${REPO} user-source
  113. )
  114. file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
  115. file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
  116. run_child(
  117. WORKING_DIRECTORY ${TOP}/user-source
  118. COMMAND ${GIT} submodule init
  119. )
  120. run_child(
  121. WORKING_DIRECTORY ${TOP}/user-source
  122. COMMAND ${GIT} submodule update
  123. )
  124. # Save the first revision name.
  125. execute_process(
  126. WORKING_DIRECTORY ${TOP}/user-source
  127. COMMAND ${GIT} rev-parse HEAD
  128. OUTPUT_VARIABLE revision1
  129. OUTPUT_STRIP_TRAILING_WHITESPACE
  130. )
  131. #-----------------------------------------------------------------------------
  132. # Create an empty commit.
  133. message("Creating empty commit...")
  134. run_child(
  135. WORKING_DIRECTORY ${TOP}/user-source
  136. COMMAND ${GIT} commit --allow-empty -m "Empty commit"
  137. )
  138. #-----------------------------------------------------------------------------
  139. # Make changes in the working tree.
  140. message("Changing content...")
  141. update_content(user-source files_added files_removed dirs_added)
  142. if(dirs_added)
  143. run_child(
  144. WORKING_DIRECTORY ${TOP}/user-source
  145. COMMAND ${GIT} add ${dirs_added}
  146. )
  147. endif()
  148. run_child(
  149. WORKING_DIRECTORY ${TOP}/user-source
  150. COMMAND ${GIT} add ${files_added}
  151. )
  152. run_child(
  153. WORKING_DIRECTORY ${TOP}/user-source
  154. COMMAND ${GIT} rm ${files_removed}
  155. )
  156. run_child(WORKING_DIRECTORY ${TOP}/user-source/module
  157. COMMAND ${GIT} checkout master
  158. )
  159. run_child(
  160. WORKING_DIRECTORY ${TOP}/user-source
  161. COMMAND ${GIT} add -u
  162. )
  163. #-----------------------------------------------------------------------------
  164. # Commit the changes to the repository.
  165. message("Committing revision 2...")
  166. run_child(
  167. WORKING_DIRECTORY ${TOP}/user-source
  168. COMMAND ${GIT} commit -m "Changed content"
  169. )
  170. run_child(
  171. WORKING_DIRECTORY ${TOP}/user-source
  172. COMMAND ${GIT} push origin
  173. )
  174. #-----------------------------------------------------------------------------
  175. # Make changes in the working tree.
  176. message("Changing content again...")
  177. change_content(user-source)
  178. run_child(
  179. WORKING_DIRECTORY ${TOP}/user-source
  180. COMMAND ${GIT} add -u
  181. )
  182. #-----------------------------------------------------------------------------
  183. # Commit the changes to the repository.
  184. message("Committing revision 3...")
  185. run_child(
  186. WORKING_DIRECTORY ${TOP}/user-source
  187. COMMAND ${GIT} commit -m "Changed content again"
  188. )
  189. run_child(
  190. WORKING_DIRECTORY ${TOP}/user-source
  191. COMMAND ${GIT} push origin
  192. )
  193. #-----------------------------------------------------------------------------
  194. # Go back to before the changes so we can test updating.
  195. macro(rewind_source src_dir)
  196. message("Backing up to revision 1...")
  197. run_child(
  198. WORKING_DIRECTORY ${TOP}/${src_dir}
  199. COMMAND ${GIT} reset --hard ${revision1}
  200. )
  201. run_child(
  202. WORKING_DIRECTORY ${TOP}/${src_dir}
  203. COMMAND ${GIT} submodule update
  204. )
  205. endmacro()
  206. rewind_source(user-source)
  207. # Make sure pull does not try to rebase (which does not work with
  208. # modified files) even if ~/.gitconfig sets "branch.master.rebase".
  209. run_child(
  210. WORKING_DIRECTORY ${TOP}/user-source
  211. COMMAND ${GIT} config branch.master.rebase false
  212. )
  213. # Create a modified file.
  214. modify_content(user-source)
  215. #-----------------------------------------------------------------------------
  216. # Test updating the user work directory with the command-line interface.
  217. message("Running CTest Dashboard Command Line...")
  218. # Create the user build tree.
  219. create_build_tree(user-source user-binary)
  220. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  221. "# GIT command configuration
  222. UpdateCommand: ${GIT}
  223. ")
  224. # Run the dashboard command line interface.
  225. set(UPDATE_NO_MODIFIED 1)
  226. run_dashboard_command_line(user-binary)
  227. set(UPDATE_NO_MODIFIED 0)
  228. rewind_source(user-source)
  229. modify_content(user-source)
  230. message("Running CTest Dashboard Command Line (custom update)...")
  231. # Create the user build tree.
  232. create_build_tree(user-source user-binary-custom)
  233. file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
  234. "# GIT command configuration
  235. UpdateCommand: ${GIT}
  236. GITUpdateCustom: ${GIT};pull;origin;master
  237. ")
  238. # Run the dashboard command line interface.
  239. run_dashboard_command_line(user-binary-custom)
  240. #-----------------------------------------------------------------------------
  241. # Test initial checkout and update with a dashboard script.
  242. message("Running CTest Dashboard Script...")
  243. create_dashboard_script(dash-binary
  244. "# git command configuration
  245. set(CTEST_GIT_COMMAND \"${GIT}\")
  246. set(CTEST_GIT_UPDATE_OPTIONS)
  247. execute_process(
  248. WORKING_DIRECTORY \"${TOP}\"
  249. COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
  250. )
  251. # Test .git file.
  252. file(RENAME \"${TOP}/dash-source/.git\" \"${TOP}/dash-source/repo.git\")
  253. file(WRITE \"${TOP}/dash-source/.git\" \"gitdir: repo.git\n\")
  254. execute_process(
  255. WORKING_DIRECTORY \"${TOP}/dash-source\"
  256. COMMAND \"${GIT}\" reset --hard ${revision1}
  257. )
  258. execute_process(
  259. WORKING_DIRECTORY \"${TOP}/dash-source\"
  260. COMMAND \"${GIT}\" submodule init
  261. )
  262. execute_process(
  263. WORKING_DIRECTORY \"${TOP}/dash-source\"
  264. COMMAND \"${GIT}\" submodule update
  265. )
  266. ")
  267. # Run the dashboard script with CTest.
  268. run_dashboard_script(dash-binary)
  269. rewind_source(dash-source)
  270. #-----------------------------------------------------------------------------
  271. # Test custom update with a dashboard script.
  272. message("Running CTest Dashboard Script (custom update)...")
  273. create_dashboard_script(dash-binary-custom
  274. "# git command configuration
  275. set(CTEST_GIT_COMMAND \"${GIT}\")
  276. set(CTEST_GIT_UPDATE_OPTIONS)
  277. set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
  278. ")
  279. # Run the dashboard script with CTest.
  280. run_dashboard_script(dash-binary-custom)