Skip to content

Commit

Permalink
git: fetch_from_repo(): introduce FETCH_FROM_REPO_CALLBACK_IF_REF_MUT…
Browse files Browse the repository at this point in the history
…ABLE

- 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
  • Loading branch information
rpardini authored and igorpecovnik committed Nov 25, 2023
1 parent 2a9ec6d commit 67b3e0d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/functions/general/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 67b3e0d

Please sign in to comment.