CTestUpdateGIT.cmake.in 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. file(WRITE ${TOP}/import/HEAD "HEAD\n")
  71. file(WRITE ${TOP}/import/master "master\n")
  72. # Import the content into the repository.
  73. run_child(WORKING_DIRECTORY ${TOP}/import
  74. COMMAND ${GIT} init
  75. )
  76. file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
  77. file(APPEND ${TOP}/import/.git/config "
  78. [remote \"origin\"]
  79. \turl = ${REPO}
  80. \tfetch = +refs/heads/*:refs/remotes/origin/*
  81. ${AUTHOR_CONFIG}")
  82. run_child(WORKING_DIRECTORY ${TOP}/import
  83. COMMAND ${GIT} add .
  84. )
  85. run_child(WORKING_DIRECTORY ${TOP}/import
  86. COMMAND ${GIT} config core.safecrlf false
  87. )
  88. run_child(WORKING_DIRECTORY ${TOP}/import
  89. COMMAND ${GIT} submodule add ${MOD_REPO} module
  90. )
  91. run_child(WORKING_DIRECTORY ${TOP}/import
  92. COMMAND ${GIT} commit -m "Initial content"
  93. )
  94. run_child(WORKING_DIRECTORY ${TOP}/import
  95. COMMAND ${GIT} push origin master:refs/heads/master
  96. )
  97. #-----------------------------------------------------------------------------
  98. # Modify the submodule.
  99. change_content(module)
  100. run_child(WORKING_DIRECTORY ${TOP}/module
  101. COMMAND ${GIT} add -u
  102. )
  103. run_child(WORKING_DIRECTORY ${TOP}/module
  104. COMMAND ${GIT} commit -m "Changed content"
  105. )
  106. run_child(WORKING_DIRECTORY ${TOP}/module
  107. COMMAND ${GIT} push origin master:refs/heads/master
  108. )
  109. #-----------------------------------------------------------------------------
  110. # Create a working tree.
  111. message("Checking out revision 1...")
  112. run_child(
  113. WORKING_DIRECTORY ${TOP}
  114. COMMAND ${GIT} clone ${REPO} user-source
  115. )
  116. file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
  117. file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
  118. run_child(
  119. WORKING_DIRECTORY ${TOP}/user-source
  120. COMMAND ${GIT} submodule init
  121. )
  122. run_child(
  123. WORKING_DIRECTORY ${TOP}/user-source
  124. COMMAND ${GIT} submodule update
  125. )
  126. # Save the first revision name.
  127. execute_process(
  128. WORKING_DIRECTORY ${TOP}/user-source
  129. COMMAND ${GIT} rev-parse HEAD
  130. OUTPUT_VARIABLE revision1
  131. OUTPUT_STRIP_TRAILING_WHITESPACE
  132. )
  133. #-----------------------------------------------------------------------------
  134. # Create an empty commit.
  135. message("Creating empty commit...")
  136. run_child(
  137. WORKING_DIRECTORY ${TOP}/user-source
  138. COMMAND ${GIT} commit --allow-empty -m "Empty commit"
  139. )
  140. #-----------------------------------------------------------------------------
  141. # Make changes in the working tree.
  142. message("Changing content...")
  143. update_content(user-source files_added files_removed dirs_added)
  144. if(dirs_added)
  145. run_child(
  146. WORKING_DIRECTORY ${TOP}/user-source
  147. COMMAND ${GIT} add -- ${dirs_added}
  148. )
  149. endif()
  150. run_child(
  151. WORKING_DIRECTORY ${TOP}/user-source
  152. COMMAND ${GIT} add -- ${files_added}
  153. )
  154. run_child(
  155. WORKING_DIRECTORY ${TOP}/user-source
  156. COMMAND ${GIT} rm -- ${files_removed}
  157. )
  158. run_child(WORKING_DIRECTORY ${TOP}/user-source/module
  159. COMMAND ${GIT} checkout master --
  160. )
  161. run_child(
  162. WORKING_DIRECTORY ${TOP}/user-source
  163. COMMAND ${GIT} add -u
  164. )
  165. #-----------------------------------------------------------------------------
  166. # Commit the changes to the repository.
  167. message("Committing revision 2...")
  168. run_child(
  169. WORKING_DIRECTORY ${TOP}/user-source
  170. COMMAND ${GIT} commit -m "Changed content"
  171. )
  172. run_child(
  173. WORKING_DIRECTORY ${TOP}/user-source
  174. COMMAND ${GIT} push origin
  175. )
  176. #-----------------------------------------------------------------------------
  177. # Make changes in the working tree.
  178. message("Changing content again...")
  179. change_content(user-source)
  180. run_child(
  181. WORKING_DIRECTORY ${TOP}/user-source
  182. COMMAND ${GIT} add -u
  183. )
  184. #-----------------------------------------------------------------------------
  185. # Commit the changes to the repository.
  186. message("Committing revision 3...")
  187. run_child(
  188. WORKING_DIRECTORY ${TOP}/user-source
  189. COMMAND ${GIT} commit -m "Changed content again"
  190. )
  191. run_child(
  192. WORKING_DIRECTORY ${TOP}/user-source
  193. COMMAND ${GIT} push origin
  194. )
  195. #-----------------------------------------------------------------------------
  196. # Go back to before the changes so we can test updating.
  197. macro(rewind_source src_dir)
  198. message("Backing up to revision 1...")
  199. run_child(
  200. WORKING_DIRECTORY ${TOP}/${src_dir}
  201. COMMAND ${GIT} reset --hard ${revision1}
  202. )
  203. run_child(
  204. WORKING_DIRECTORY ${TOP}/${src_dir}
  205. COMMAND ${GIT} submodule update
  206. )
  207. endmacro()
  208. rewind_source(user-source)
  209. # Make sure pull does not try to rebase (which does not work with
  210. # modified files) even if ~/.gitconfig sets "branch.master.rebase".
  211. run_child(
  212. WORKING_DIRECTORY ${TOP}/user-source
  213. COMMAND ${GIT} config branch.master.rebase false
  214. )
  215. # Create a modified file.
  216. modify_content(user-source)
  217. #-----------------------------------------------------------------------------
  218. # Test updating the user work directory with the command-line interface.
  219. message("Running CTest Dashboard Command Line...")
  220. # Create the user build tree.
  221. create_build_tree(user-source user-binary)
  222. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  223. "# GIT command configuration
  224. UpdateCommand: ${GIT}
  225. ")
  226. # Run the dashboard command line interface.
  227. set(UPDATE_NO_MODIFIED 1)
  228. run_dashboard_command_line(user-binary)
  229. set(UPDATE_NO_MODIFIED 0)
  230. rewind_source(user-source)
  231. modify_content(user-source)
  232. message("Running CTest Dashboard Command Line (custom update)...")
  233. # Create the user build tree.
  234. create_build_tree(user-source user-binary-custom)
  235. file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
  236. "# GIT command configuration
  237. UpdateCommand: ${GIT}
  238. GITUpdateCustom: ${GIT};pull;origin;master
  239. ")
  240. # Run the dashboard command line interface.
  241. run_dashboard_command_line(user-binary-custom)
  242. #-----------------------------------------------------------------------------
  243. # Test initial checkout and update with a dashboard script.
  244. message("Running CTest Dashboard Script...")
  245. create_dashboard_script(dash-binary
  246. "# git command configuration
  247. set(CTEST_GIT_COMMAND \"${GIT}\")
  248. set(CTEST_GIT_UPDATE_OPTIONS)
  249. execute_process(
  250. WORKING_DIRECTORY \"${TOP}\"
  251. COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
  252. )
  253. # Test .git file.
  254. file(RENAME \"${TOP}/dash-source/.git\" \"${TOP}/dash-source/repo.git\")
  255. file(WRITE \"${TOP}/dash-source/.git\" \"gitdir: repo.git\n\")
  256. execute_process(
  257. WORKING_DIRECTORY \"${TOP}/dash-source\"
  258. COMMAND \"${GIT}\" reset --hard ${revision1}
  259. )
  260. execute_process(
  261. WORKING_DIRECTORY \"${TOP}/dash-source\"
  262. COMMAND \"${GIT}\" submodule init
  263. )
  264. execute_process(
  265. WORKING_DIRECTORY \"${TOP}/dash-source\"
  266. COMMAND \"${GIT}\" submodule update
  267. )
  268. ")
  269. # Run the dashboard script with CTest.
  270. run_dashboard_script(dash-binary)
  271. rewind_source(dash-source)
  272. #-----------------------------------------------------------------------------
  273. # Test custom update with a dashboard script.
  274. message("Running CTest Dashboard Script (custom update)...")
  275. create_dashboard_script(dash-binary-custom
  276. "# git command configuration
  277. set(CTEST_GIT_COMMAND \"${GIT}\")
  278. set(CTEST_GIT_UPDATE_OPTIONS)
  279. set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
  280. ")
  281. # Run the dashboard script with CTest.
  282. run_dashboard_script(dash-binary-custom)