From c0621c77efa42fc2ade968acffa0a912321ad84d Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Sat, 18 May 2024 00:33:44 +0500 Subject: [PATCH] internal: teach gather_pr_locally.cmake to create temp branch (#1973) --- misc/gather_prs_locally.cmake | 36 +++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/misc/gather_prs_locally.cmake b/misc/gather_prs_locally.cmake index bf0bd7a8a4..c4e033d2ea 100644 --- a/misc/gather_prs_locally.cmake +++ b/misc/gather_prs_locally.cmake @@ -12,8 +12,6 @@ set(PSEUDO_BINARY_DIR "./build") include(${CMAKE_SOURCE_DIR}/cmake/yarn.cmake) -message(STATUS "Downloading Pospelove/auto-merge-action@main (dist/index.js)") - message(STATUS "Downloading ${AUTO_MERGE_REPO}@${AUTO_MERGE_BRANCH} (dist/index.js)") file(REMOVE_RECURSE ${PSEUDO_BINARY_DIR}/auto-merge-action) @@ -67,6 +65,40 @@ else() message(FATAL_ERROR "Failed to run Pospelove/auto-merge-action@main: ${NODE_OUTPUT}") endif() +# if branch is main, then do git switch -c gather-prs- + +execute_process( + COMMAND git branch --show-current + OUTPUT_VARIABLE CURRENT_BRANCH + RESULT_VARIABLE GIT_COMMIT_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(NOT GIT_COMMIT_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to get the current branch: ${GIT_COMMIT_RESULT} ${CURRENT_BRANCH}") +endif() + +message(STATUS "Current branch: ${CURRENT_BRANCH}") + +if(CURRENT_BRANCH MATCHES main) + message(STATUS "Main branch detected. Switching to a temporary branch") + + string(TIMESTAMP TIMESTAMP "%Y%m%d%H%M%S") + set(TEMP_BRANCH "gather-prs-${TIMESTAMP}") + + execute_process( + COMMAND git switch -c ${TEMP_BRANCH} + RESULT_VARIABLE GIT_SWITCH_RESULT + OUTPUT_VARIABLE GIT_SWITCH_OUTPUT + ) + + if(GIT_SWITCH_RESULT EQUAL 0) + message(STATUS "Switched to a temporary branch ${TEMP_BRANCH}") + else() + message(FATAL_ERROR "Failed to switch to a temporary branch: ${GIT_SWITCH_OUTPUT}") + endif() +endif() + # Commit the changes locally # git add . && git commit -m "Gather PRs"