Skip to content

Commit dda0abf

Browse files
committed
fix: checkout to the previous branch if switch back fails
1 parent 0652dee commit dda0abf

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/Git.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,17 @@ function(git_switch_back)
457457

458458
execute_process(
459459
COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}"
460-
COMMAND_ERROR_IS_FATAL LAST
460+
RESULT_VARIABLE _switch_back_result
461461
)
462+
463+
# if the switch back failed, try to checkout the previous branch
464+
if(NOT ${_switch_back_result} EQUAL 0)
465+
message(STATUS "Switch back failed. Trying to checkout previous branch")
466+
execute_process(
467+
COMMAND "${GIT_EXECUTABLE}" "checkout" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}"
468+
COMMAND_ERROR_IS_FATAL LAST
469+
)
470+
endif()
462471
endif()
463472
endfunction()
464473

0 commit comments

Comments
 (0)