From ab1d9d4f7920d708cc473ca048c6198e29a02be6 Mon Sep 17 00:00:00 2001 From: sunhaoyi Date: Wed, 4 Sep 2024 12:14:14 +0800 Subject: [PATCH] util: Support for using commit numbers to manage repo version Signed-off-by: sunhaoyi --- util.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util.sh b/util.sh index 368b75b..a8f0c76 100644 --- a/util.sh +++ b/util.sh @@ -94,10 +94,19 @@ function clone_repo() { repo_name=${3:-$(echo "$1" | jq -r ".name")} clone_to=${2}/${repo_name} repo_url=$(echo "$1" | jq -r ".url") + repo_target=$(echo "$1" | jq -r ".revision") + rm -rf ${clone_to} + if [[ ${repo_target} != null ]]; then + git clone --recurse-submodules -q --depth 1 --branch ${DEF_VERSION} --no-tags ${repo_url} ${clone_to} 1>/dev/null 2>&1 + cd ${clone_to} + git fetch -f --depth=1 ${repo_url} ${repo_target} 1>/dev/null 2>&1 + git checkout ${repo_target} 1>/dev/null 2>&1 + cd - 1>/dev/null 2>&1 + return 0 + fi repo_target=$(echo "$1" | jq -r ".version") && [[ ${repo_target} != null ]] || repo_target=$(echo "$1" | jq -r ".branch") && [[ ${repo_target} != null ]] || repo_target=${DEF_VERSION} - rm -rf ${clone_to} git clone --recurse-submodules -q --depth 1 --branch ${repo_target} --no-tags ${repo_url} ${clone_to} 1>/dev/null 2>&1 } @@ -124,7 +133,8 @@ function update_repo() { repo_name=${3:-$(echo "$1" | jq -r ".name")} repo_path=${2}/${repo_name} repo_url=$(echo "$1" | jq -r ".url") - repo_target=$(echo "$1" | jq -r ".version") && [[ ${repo_target} != null ]] || + repo_target=$(echo "$1" | jq -r ".revision") && [[ ${repo_target} != null ]] || + repo_target=$(echo "$1" | jq -r ".version") && [[ ${repo_target} != null ]] || repo_target=$(echo "$1" | jq -r ".branch") && [[ ${repo_target} != null ]] || repo_target=${DEF_VERSION} -- Gitee