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 <alexandru.croitor@qt.io>
This commit is contained in:
Volker Hilsheimer
2020-12-02 09:45:14 +01:00
parent 5bbec95c48
commit 6e619b06d7

View File

@@ -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()