Skip to content

Commit 5e62f1f

Browse files
committed
Re-fix apply_patches cmake function.
1 parent 14f265d commit 5e62f1f

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

cmake/modules/CMakeFunctions.cmake

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,29 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
5050
return()
5151
endif()
5252

53+
message(STATUS "${repo_dir}:")
54+
# Check if the target branch already exists
5355
execute_process(
54-
COMMAND ${GIT_EXECUTABLE} rev-list -1 HEAD
56+
COMMAND ${GIT_EXECUTABLE} rev-parse --verify --no-revs -q ${target_branch}
5557
WORKING_DIRECTORY ${repo_dir}
56-
OUTPUT_VARIABLE current_branch
57-
OUTPUT_STRIP_TRAILING_WHITESPACE
58+
RESULT_VARIABLE patches_needed
5859
)
59-
if(${current_branch} STREQUAL ${target_branch})
60-
message(STATUS "Source files in ${repo_dir} are already patched")
61-
return()
60+
if(patches_needed) # The target branch doesn't exist
61+
list(SORT patches)
62+
execute_process( # Create the target branch
63+
COMMAND ${GIT_EXECUTABLE} checkout -b ${target_branch} ${base_revision}
64+
WORKING_DIRECTORY ${repo_dir}
65+
)
66+
execute_process( # Apply the pathces
67+
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patches}
68+
WORKING_DIRECTORY ${repo_dir}
69+
)
70+
else() # The target branch already exists
71+
execute_process( # Check it out
72+
COMMAND ${GIT_EXECUTABLE} checkout ${target_branch}
73+
WORKING_DIRECTORY ${repo_dir}
74+
)
6275
endif()
63-
64-
list(SORT patches)
65-
execute_process(
66-
COMMAND ${GIT_EXECUTABLE} checkout -b ${target_branch} ${base_revision}
67-
WORKING_DIRECTORY ${repo_dir}
68-
)
69-
execute_process(
70-
COMMAND ${GIT_EXECUTABLE} am --3way --ignore-whitespace ${patches}
71-
WORKING_DIRECTORY ${repo_dir}
72-
)
7376
endfunction()
7477

7578
# Usage

0 commit comments

Comments
 (0)