1 # This script drives creation of a git repository and checks
2 # that CTest can update from it.
4 #-----------------------------------------------------------------------------
5 # Test in a directory next to this script.
6 get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
7 string(APPEND TOP "/@CTestUpdateGIT_DIR@")
8 set(UPDATE_EXTRA Updated{module})
10 # Include code common to all update tests.
11 include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
13 #-----------------------------------------------------------------------------
14 # Report git tools in use.
15 message("Using GIT tools:")
16 set(GIT "@GIT_EXECUTABLE@")
17 message(" git = ${GIT}")
19 set(AUTHOR_CONFIG "[user]
21 \temail = testauthor@cmake.org
24 #-----------------------------------------------------------------------------
25 # Initialize the testing directory.
26 message("Creating test directory...")
30 set(src "@CMAKE_CURRENT_SOURCE_DIR@")
31 configure_file(${src}/CTestUpdateGIT.sh.in ${TOP}/git.sh @ONLY)
32 set(GIT ${TOP}/git.sh)
35 # Adapt to the system default branch name.
37 COMMAND ${GIT} --git-dir= config --get init.defaultBranch
38 RESULT_VARIABLE defaultBranchFailed
39 OUTPUT_VARIABLE defaultBranch
40 ERROR_VARIABLE defaultBranchError
41 OUTPUT_STRIP_TRAILING_WHITESPACE
42 ERROR_STRIP_TRAILING_WHITESPACE
44 if(defaultBranch STREQUAL "")
45 set(defaultBranch master)
47 message("Detected default branch name '${defaultBranch}'")
49 #-----------------------------------------------------------------------------
50 # Create the repository.
51 message("Creating repository...")
52 file(MAKE_DIRECTORY ${TOP}/repo.git)
54 WORKING_DIRECTORY ${TOP}/repo.git
55 COMMAND ${GIT} --bare init
57 file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
59 # Create submodule repository.
60 message("Creating submodule...")
61 file(MAKE_DIRECTORY ${TOP}/module.git)
63 WORKING_DIRECTORY ${TOP}/module.git
64 COMMAND ${GIT} --bare init
66 file(REMOVE_RECURSE ${TOP}/module.git/hooks)
67 run_child(WORKING_DIRECTORY ${TOP}
68 COMMAND ${GIT} clone module.git module
70 file(REMOVE_RECURSE ${TOP}/module/.git/hooks)
71 file(APPEND ${TOP}/module/.git/config "
73 create_content(module)
74 run_child(WORKING_DIRECTORY ${TOP}/module
77 run_child(WORKING_DIRECTORY ${TOP}/module
78 COMMAND ${GIT} commit -m "Initial content"
80 run_child(WORKING_DIRECTORY ${TOP}/module
81 COMMAND ${GIT} push origin ${defaultBranch}:refs/heads/${defaultBranch}
84 #-----------------------------------------------------------------------------
85 # Import initial content into the repository.
86 message("Importing content...")
88 # Import the content into the repository.
89 run_child(WORKING_DIRECTORY ${TOP}
90 COMMAND ${GIT} clone repo.git import
92 file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
93 file(APPEND ${TOP}/import/.git/config "
95 create_content(import)
96 file(WRITE ${TOP}/import/HEAD "HEAD\n")
97 file(WRITE ${TOP}/import/${defaultBranch} "${defaultBranch}\n")
98 run_child(WORKING_DIRECTORY ${TOP}/import
101 run_child(WORKING_DIRECTORY ${TOP}/import
102 COMMAND ${GIT} config core.safecrlf false
104 run_child(WORKING_DIRECTORY ${TOP}/import
105 COMMAND ${GIT} submodule add ../module.git module
107 run_child(WORKING_DIRECTORY ${TOP}/import
108 COMMAND ${GIT} commit -m "Initial content"
110 run_child(WORKING_DIRECTORY ${TOP}/import
111 COMMAND ${GIT} push origin ${defaultBranch}:refs/heads/${defaultBranch}
114 #-----------------------------------------------------------------------------
115 # Modify the submodule.
116 change_content(module)
117 run_child(WORKING_DIRECTORY ${TOP}/module
118 COMMAND ${GIT} add -u
120 run_child(WORKING_DIRECTORY ${TOP}/module
121 COMMAND ${GIT} commit -m "Changed content"
123 run_child(WORKING_DIRECTORY ${TOP}/module
124 COMMAND ${GIT} push origin ${defaultBranch}:refs/heads/${defaultBranch}
127 #-----------------------------------------------------------------------------
128 # Create a working tree.
129 message("Checking out revision 1...")
131 WORKING_DIRECTORY ${TOP}
132 COMMAND ${GIT} clone repo.git user-source
134 file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
135 file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
137 WORKING_DIRECTORY ${TOP}/user-source
138 COMMAND ${GIT} submodule init
141 WORKING_DIRECTORY ${TOP}/user-source
142 COMMAND ${GIT} submodule update
145 # Save the first revision name.
147 WORKING_DIRECTORY ${TOP}/user-source
148 COMMAND ${GIT} rev-parse HEAD
149 OUTPUT_VARIABLE revision1
150 OUTPUT_STRIP_TRAILING_WHITESPACE
153 #-----------------------------------------------------------------------------
154 # Create an empty commit.
155 message("Creating empty commit...")
157 WORKING_DIRECTORY ${TOP}/user-source
158 COMMAND ${GIT} commit --allow-empty -m "Empty commit"
161 #-----------------------------------------------------------------------------
162 # Make changes in the working tree.
163 message("Changing content...")
164 update_content(user-source files_added files_removed dirs_added)
167 WORKING_DIRECTORY ${TOP}/user-source
168 COMMAND ${GIT} add -- ${dirs_added}
172 WORKING_DIRECTORY ${TOP}/user-source
173 COMMAND ${GIT} add -- ${files_added}
176 WORKING_DIRECTORY ${TOP}/user-source
177 COMMAND ${GIT} rm -- ${files_removed}
179 run_child(WORKING_DIRECTORY ${TOP}/user-source/module
180 COMMAND ${GIT} checkout ${defaultBranch} --
183 WORKING_DIRECTORY ${TOP}/user-source
184 COMMAND ${GIT} add -u
187 #-----------------------------------------------------------------------------
188 # Commit the changes to the repository.
189 message("Committing revision 2...")
191 WORKING_DIRECTORY ${TOP}/user-source
192 COMMAND ${GIT} commit -m "Changed content"
195 WORKING_DIRECTORY ${TOP}/user-source
196 COMMAND ${GIT} push origin HEAD
199 #-----------------------------------------------------------------------------
200 # Make changes in the working tree.
201 message("Changing content again...")
202 change_content(user-source)
204 WORKING_DIRECTORY ${TOP}/user-source
205 COMMAND ${GIT} add -u
208 #-----------------------------------------------------------------------------
209 # Commit the changes to the repository.
210 message("Committing revision 3...")
212 WORKING_DIRECTORY ${TOP}/user-source
213 COMMAND ${GIT} commit -m "Changed content again"
216 WORKING_DIRECTORY ${TOP}/user-source
217 COMMAND ${GIT} push origin HEAD
220 #-----------------------------------------------------------------------------
221 # Go back to before the changes so we can test updating.
222 macro(rewind_source src_dir)
223 message("Backing up to revision 1...")
225 WORKING_DIRECTORY ${TOP}/${src_dir}
226 COMMAND ${GIT} reset --hard ${revision1}
229 WORKING_DIRECTORY ${TOP}/${src_dir}
230 COMMAND ${GIT} submodule update
233 rewind_source(user-source)
235 # Make sure pull does not try to rebase (which does not work with
236 # modified files) even if ~/.gitconfig sets "branch.master.rebase".
238 WORKING_DIRECTORY ${TOP}/user-source
239 COMMAND ${GIT} config branch.${defaultBranch}.rebase false
242 # Create a modified file.
243 modify_content(user-source)
245 #-----------------------------------------------------------------------------
246 # Test updating the user work directory with the command-line interface.
247 message("Running CTest Dashboard Command Line...")
249 # Create the user build tree.
250 create_build_tree(user-source user-binary)
251 file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
252 "# GIT command configuration
253 UpdateCommand: ${GIT}
256 # Run the dashboard command line interface.
257 set(UPDATE_NO_MODIFIED 1)
258 run_dashboard_command_line(user-binary)
259 set(UPDATE_NO_MODIFIED 0)
261 rewind_source(user-source)
262 modify_content(user-source)
264 message("Running CTest Dashboard Command Line (custom update)...")
266 # Create the user build tree.
267 create_build_tree(user-source user-binary-custom)
268 file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
269 "# GIT command configuration
270 UpdateCommand: ${GIT}
271 GITUpdateCustom: ${GIT};pull;origin;${defaultBranch}
274 # Run the dashboard command line interface.
275 run_dashboard_command_line(user-binary-custom)
277 #-----------------------------------------------------------------------------
278 # Test initial checkout and update with a dashboard script.
279 message("Running CTest Dashboard Script...")
281 create_dashboard_script(dash-binary
282 "# git command configuration
283 set(CTEST_GIT_COMMAND \"${GIT}\")
284 set(CTEST_GIT_UPDATE_OPTIONS)
286 WORKING_DIRECTORY \"${TOP}\"
287 COMMAND \"${GIT}\" clone repo.git dash-source
291 file(RENAME \"${TOP}/dash-source/.git\" \"${TOP}/dash-source/repo.git\")
292 file(WRITE \"${TOP}/dash-source/.git\" \"gitdir: repo.git\n\")
295 WORKING_DIRECTORY \"${TOP}/dash-source\"
296 COMMAND \"${GIT}\" reset --hard ${revision1}
299 WORKING_DIRECTORY \"${TOP}/dash-source\"
300 COMMAND \"${GIT}\" submodule init
303 WORKING_DIRECTORY \"${TOP}/dash-source\"
304 COMMAND \"${GIT}\" submodule update
308 # Run the dashboard script with CTest.
309 run_dashboard_script(dash-binary)
311 rewind_source(dash-source)
313 #-----------------------------------------------------------------------------
314 # Test custom update with a dashboard script.
315 message("Running CTest Dashboard Script (custom update)...")
317 create_dashboard_script(dash-binary-custom
318 "# git command configuration
319 set(CTEST_GIT_COMMAND \"${GIT}\")
320 set(CTEST_GIT_UPDATE_OPTIONS)
321 set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin ${defaultBranch})
324 # Run the dashboard script with CTest.
325 run_dashboard_script(dash-binary-custom)
328 rewind_source(dash-source)
330 #-----------------------------------------------------------------------------
331 # Test no update with a dashboard script.
332 message("Running CTest Dashboard Script (No update)...")
334 create_dashboard_script(dash-binary-no-update
335 "# git command configuration
336 set(CTEST_GIT_COMMAND \"${GIT}\")
337 set(CTEST_UPDATE_VERSION_ONLY TRUE)
340 # Run the dashboard script with CTest.
342 run_dashboard_script(dash-binary-no-update)
345 rewind_source(dash-source)
347 #-----------------------------------------------------------------------------
348 # Test ctest_update(QUIET)
349 message("Running CTest Dashboard Script (update quietly)...")
351 set(ctest_update_args QUIET)
352 create_dashboard_script(dash-binary-quiet
353 "# git command configuration
354 set(CTEST_GIT_COMMAND \"${GIT}\")
355 set(CTEST_GIT_UPDATE_OPTIONS)
356 set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin ${defaultBranch})
358 unset(ctest_update_args)
360 # Run the dashboard script with CTest.
361 run_dashboard_script(dash-binary-quiet)
363 # Make sure the output seems quiet.
364 if("${OUTPUT}" MATCHES "Updating the repository")
365 message(FATAL_ERROR "Found 'Updating the repository' in quiet output")
368 #-----------------------------------------------------------------------------
369 # Test ctest_update(RETURN_VALUE) on failure
370 message("Running CTest Dashboard Script (fail to update)...")
372 set(ctest_update_check [[
375 message(FATAL_ERROR "ctest_update incorrectly succeeded with ${ret}")
378 create_dashboard_script(dash-binary-fail
379 "set(CTEST_GIT_COMMAND \"update-command-does-not-exist\")
381 unset(ctest_update_check)
383 # Run the dashboard script with CTest.
385 run_dashboard_script(dash-binary-fail)