From 343a7ef4fe8fca75d02dd063a709041a4a299fb5 Mon Sep 17 00:00:00 2001 From: clsty Date: Thu, 2 Oct 2025 18:47:14 +0800 Subject: [PATCH] Add git_unshallow and latest_commit_hash --- scriptdata/functions.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scriptdata/functions.sh b/scriptdata/functions.sh index 531df3ef3..208c48b28 100644 --- a/scriptdata/functions.sh +++ b/scriptdata/functions.sh @@ -75,3 +75,17 @@ function prevent_sudo_or_root(){ root) echo -e "${STY_RED}[$0]: This script is NOT to be executed with sudo or as root. Aborting...${STY_RESET}";exit 1;; esac } +function git_unshallow(){ +# We need this function for latest_commit_hash to work properly + if [[ -f "$(git rev-parse --git-dir)/shallow" ]]; then + echo "Shallow clone detected. Unshallowing..." + git fetch --unshallow + fi +} +function latest_commit_hash(){ + local target_path="$1" + if [[ ! -e "$target_path" ]]; then + echo "[latest_commit_hash] '$target_path' does not exist. Aborting...";exit 1 + fi + echo $(git log -1 --format="%H" -- "$target_path" 2>/dev/null) +}