armbian-next: git: fetch_from_repo(): add fetched_revision(_ts) as well as checked_out_revision(_ts); introduce param do_checkout=no to only fetch, not checkout

This commit is contained in:
Ricardo Pardini
2023-01-27 13:09:03 +01:00
parent 1291c6cc3a
commit 5fa7bf735b

View File

@@ -194,31 +194,40 @@ function fetch_from_repo() {
branch)
improved_git_fetch --no-tags "${url}" "${ref_name}"
;;
commit)
# @TODO: if the local copy has the revision, skip the fetch -- would save us a lot of time
display_alert "Fetching a specific commit/sha1" "${ref_name}" "debug"
improved_git_fetch --no-tags "${url}" "${ref_name}"
;;
tag)
improved_git_fetch --no-tags "${url}" tags/"${ref_name}"
;;
head)
improved_git_fetch --no-tags "${url}" HEAD
;;
commit)
# @TODO: if the local copy has the revision, skip the fetch -- would save us a lot of time
display_alert "Fetching a specific commit/sha1" "${ref_name}" "debug"
improved_git_fetch --no-tags "${url}" "${ref_name}"
;;
esac
display_alert "Fetch from remote completed, checking out..." "$dir $ref_name" "info"
checkout_from="FETCH_HEAD"
fi
# should be declared in outside scope, so can be read.
checked_out_revision="$(git rev-parse "${checkout_from}")" # Don't fail nor output anything if failure
display_alert "Checked out revision" "${checked_out_revision}" "debug" # @TODO change to git
checked_out_revision_ts="$(git log -1 --pretty=%ct "${checkout_from}")" # unix timestamp of the commit date
display_alert "checked_out_revision_ts set!" "${checked_out_revision_ts}" "git"
# if the tree is shallow and big, this first rev-parse takes a while; use info to inform about what is done
display_alert "git: Fetch from remote completed, rev-parsing..." "'$dir' '$ref_name' '${checkout_from}'" "info"
display_alert "git checking out revision SHA" "${checked_out_revision}" "git"
regular_git checkout -f -q "${checked_out_revision}" # Return the files that are tracked by git to the initial state.
# should be declared in outer scope: fetched_revision fetched_revision_ts
fetched_revision="$(git rev-parse "${checkout_from}")"
fetched_revision_ts="$(git log -1 --pretty=%ct "${checkout_from}")" # unix timestamp of the commit date
display_alert "Fetched revision: fetched_revision:" "${fetched_revision}" "git"
display_alert "Fetched revision: fetched_revision_ts:" "${fetched_revision_ts}" "git"
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.
# should be declared in outer scope: checked_out_revision checked_out_revision_ts
checked_out_revision="${fetched_revision}"
checked_out_revision_ts="${fetched_revision_ts}"
display_alert "Fetched revision: checked_out_revision:" "${checked_out_revision}" "git"
display_alert "Fetched revision: checked_out_revision_ts:" "${checked_out_revision_ts}" "git"
display_alert "git cleaning" "${checked_out_revision}" "git"
regular_git clean -q -d -f # Removes files that are not tracked by git. Does not remove .gitignore'd files.
@@ -245,4 +254,9 @@ function fetch_from_repo() {
done
fi
fi
else
display_alert "Skipping checkout" "$dir $ref_name ${checked_out_revision}" "warn"
fi
return 0
}