Skip to content

Commit

Permalink
fix: checkout to the previous branch if switch back fails
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 17, 2024
1 parent 0652dee commit dda0abf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,17 @@ function(git_switch_back)

execute_process(
COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}"
COMMAND_ERROR_IS_FATAL LAST
RESULT_VARIABLE _switch_back_result
)

# if the switch back failed, try to checkout the previous branch
if(NOT ${_switch_back_result} EQUAL 0)
message(STATUS "Switch back failed. Trying to checkout previous branch")
execute_process(
COMMAND "${GIT_EXECUTABLE}" "checkout" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}"
COMMAND_ERROR_IS_FATAL LAST
)
endif()
endif()
endfunction()

Expand Down

0 comments on commit dda0abf

Please sign in to comment.