summaryrefslogtreecommitdiffstats
path: root/Modules/ExternalProject.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-04-03 18:34:35 (GMT)
committerBrad King <brad.king@kitware.com>2017-04-03 18:34:35 (GMT)
commit12a781301c41f187b8d91ffd4461820c42bdaf5a (patch)
tree1e6dbd54cdfe00e45b4c05e46ccc7b749a942eb7 /Modules/ExternalProject.cmake
parent53e9c2d2a31f33f5d72c2df5558ffa7213a54a04 (diff)
downloadCMake-12a781301c41f187b8d91ffd4461820c42bdaf5a.zip
CMake-12a781301c41f187b8d91ffd4461820c42bdaf5a.tar.gz
CMake-12a781301c41f187b8d91ffd4461820c42bdaf5a.tar.bz2
ExternalProject: Run `git checkout` with `--` to clarify arguments
Fix the case when the tag name to be checked out also happens to match a path name. Unfortunately we cannot do this for Git versions prior to 1.8.5 because they do not "do what I mean" to checkout remote branches when the `--` argument is given. Fixes: #16678
Diffstat (limited to 'Modules/ExternalProject.cmake')
-rw-r--r--Modules/ExternalProject.cmake14
1 files changed, 10 insertions, 4 deletions
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 34dc98c..b812845 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -531,6 +531,15 @@ function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git
else()
set(git_clone_shallow_options "--depth 1")
endif()
+ if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5)
+ # Use `git checkout <tree-ish> --` to avoid ambiguity with a local path.
+ set(git_checkout_explicit-- "--")
+ else()
+ # Use `git checkout <branch>` even though this risks ambiguity with a
+ # local path. Unfortunately we cannot use `git checkout <tree-ish> --`
+ # because that will not search for remote branch names, a common use case.
+ set(git_checkout_explicit-- "")
+ endif()
file(WRITE ${script_filename}
"if(\"${git_tag}\" STREQUAL \"\")
message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
@@ -600,11 +609,8 @@ if(error_code)
message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
endif()
-# Use `git checkout <branch>` even though this risks ambiguity with a
-# local path. Unfortunately we cannot use `git checkout <tree-ish> --`
-# because that will not search for remote branch names, a common use case.
execute_process(
- COMMAND \"${git_EXECUTABLE}\" \${git_options} checkout ${git_tag}
+ COMMAND \"${git_EXECUTABLE}\" \${git_options} checkout ${git_tag} ${git_checkout_explicit--}
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)