@@ -44,7 +44,7 @@ endmacro(use_eh)
4444# Then all patches from the `patches_dir` are committed to the `target_branch`.
4545# Does nothing if the `target_branch` is already checked out in the `repo_dir`.
4646#
47- function (apply_patches repo_dir patches_dir base_revision target_branch)
47+ function (apply_patches repo_dir patches_dir base_revision target_branch ret )
4848 file (GLOB patches ${patches_dir} /*.patch)
4949 if (NOT patches)
5050 message (STATUS "No patches in ${patches_dir} " )
@@ -58,22 +58,30 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
5858 WORKING_DIRECTORY ${repo_dir}
5959 RESULT_VARIABLE patches_needed
6060 )
61- if (patches_needed) # The target branch doesn't exist
61+ if (patches_needed EQUAL 128) # not a git repo
62+ set (ret_not_git_repo 1)
63+ elseif (patches_needed) # The target branch doesn't exist
6264 list (SORT patches)
6365 execute_process ( # Create the target branch
6466 COMMAND ${GIT_EXECUTABLE} checkout -b ${target_branch} ${base_revision}
6567 WORKING_DIRECTORY ${repo_dir}
68+ RESULT_VARIABLE ret_check_out
6669 )
6770 execute_process ( # Apply the pathces
6871 COMMAND ${GIT_EXECUTABLE} am --3way --ignore -whitespace ${patches}
6972 WORKING_DIRECTORY ${repo_dir}
73+ RESULT_VARIABLE ret_apply_patch
7074 )
7175 else () # The target branch already exists
7276 execute_process ( # Check it out
7377 COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
7478 WORKING_DIRECTORY ${repo_dir}
79+ RESULT_VARIABLE ret_check_out
7580 )
7681 endif ()
82+ if (NOT (ret_not_git_repo OR ret_check_out OR ret_apply_patch))
83+ set (${ret} True PARENT_SCOPE)
84+ endif ()
7785endfunction ()
7886
7987# Usage
0 commit comments