From 67b3e0dd07223d597a5c89e48c34e12343238410 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sat, 18 Nov 2023 11:56:15 +0100 Subject: [PATCH] git: fetch_from_repo(): introduce FETCH_FROM_REPO_CALLBACK_IF_REF_MUTABLE - function defined in FETCH_FROM_REPO_CALLBACK_IF_REF_MUTABLE is called if reference is mutable - which is anything that's not `commit:` or `tag:` - and really there's no guarantee that `tag:` is immutable, but lets assume --- lib/functions/general/git.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/functions/general/git.sh b/lib/functions/general/git.sh index cf634a62eed2..fbf67028cf51 100644 --- a/lib/functions/general/git.sh +++ b/lib/functions/general/git.sh @@ -240,6 +240,18 @@ function fetch_from_repo() { display_alert "Fetched revision: fetched_revision:" "${fetched_revision}" "git" display_alert "Fetched revision: fetched_revision_ts:" "${fetched_revision_ts}" "git" + # if FETCH_FROM_REPO_CALLBACK_IF_REF_MUTABLE is set, and the ref is not a sha1, invoke that callback. + if [[ "${FETCH_FROM_REPO_CALLBACK_IF_REF_MUTABLE:-"none"}" != "none" ]]; then + case $ref_type in + tag | commit) # do nothing + ;; + *) # Complain + display_alert "FETCH_FROM_REPO_CALLBACK_IF_REF_MUTABLE is set, and the ref is not a sha1" "${url} ${ref_type} ${ref_name} - should be commit:${fetched_revision}" "debug" + "${FETCH_FROM_REPO_CALLBACK_IF_REF_MUTABLE}" "${url}" "${ref_type}" "${ref_name}" "${fetched_revision}" + ;; + esac + fi + if [[ "${do_checkout:-"yes"}" == "yes" ]]; then display_alert "git checking out revision SHA" "${fetched_revision}" "git" regular_git checkout -f -q "${fetched_revision}" # Return the files that are tracked by git to the initial state.