From 6e619b06d7c9af4a95916485ac46825947abf7e8 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 2 Dec 2020 09:45:14 +0100 Subject: [PATCH] Checkout as detached if checking out branch fails Having several toplevel worktrees for the same branch is problematic, but but we do want to be able to have one toplevel worktree synchronized to e.g. one submodule's dev and another with all submodules at the respective dev heads. So fall back to detached checkout if regular checkout fails, and generate a warning. Change-Id: I13981ab931cbbd8b56187979708bfe63f7373718 Reviewed-by: Alexandru Croitor --- cmake/QtTopLevelHelpers.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmake/QtTopLevelHelpers.cmake b/cmake/QtTopLevelHelpers.cmake index 990013f5..6287d935 100644 --- a/cmake/QtTopLevelHelpers.cmake +++ b/cmake/QtTopLevelHelpers.cmake @@ -131,6 +131,15 @@ function(qt_internal_checkout module revision) RESULT_VARIABLE git_result ${swallow_output} ) + if (git_result EQUAL 128) + message(WARNING "${git_output}, trying detached checkout") + execute_process( + COMMAND "git" "checkout" "--detach" "${revision}" + WORKING_DIRECTORY "./${module}" + RESULT_VARIABLE git_result + ${swallow_output} + ) + endif() if (git_result) message(FATAL_ERROR "Failed to check '${module}' out to '${revision}': ${git_output}") endif()