From 7c9241ff895ffc86e1f38f35b26e6b5edca270bd Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Thu, 27 Feb 2020 22:37:51 +0100 Subject: [PATCH] Add support for commit HASH. Shallow checkout works only on recent Git servers. It works on Google kernel mirrot, but not on kernel.org --- lib/general.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/general.sh b/lib/general.sh index 6848f432dd..013f8b49c9 100644 --- a/lib/general.sh +++ b/lib/general.sh @@ -191,10 +191,10 @@ create_sources_list() # branch:name # tag:name # head(*) -# commit:hash@depth(**) +# commit:hash # # *: Implies ref_subdir=no -# **: Not implemented yet +# # : "yes" to create subdirectory for tag or branch name # fetch_from_repo() @@ -204,7 +204,7 @@ fetch_from_repo() local ref=$3 local ref_subdir=$4 - [[ -z $ref || ( $ref != tag:* && $ref != branch:* && $ref != head ) ]] && exit_with_error "Error in configuration" + [[ -z $ref || ( $ref != tag:* && $ref != branch:* && $ref != head && $ref != commit:* ) ]] && exit_with_error "Error in configuration" local ref_type=${ref%%:*} if [[ $ref_type == head ]]; then local ref_name=HEAD @@ -246,6 +246,7 @@ fetch_from_repo() local changed=false local local_hash=$(git rev-parse @ 2>/dev/null) + case $ref_type in branch) # TODO: grep refs/heads/$name @@ -265,19 +266,30 @@ fetch_from_repo() local remote_hash=$(git ls-remote $url HEAD | cut -f1) [[ -z $local_hash || $local_hash != $remote_hash ]] && changed=true ;; + + commit) + [[ -z $local_hash || $local_hash == "@" ]] && changed=true + ;; esac + if [[ $changed == true ]]; then # remote was updated, fetch and check out updates display_alert "Fetching updates" case $ref_type in branch) git fetch --depth 1 origin $ref_name ;; - tag) git fetch --depth 1 origin tags/$ref_name ;; + tag) ;; head) git fetch --depth 1 origin HEAD ;; + commit) git fetch --depth 1 origin $ref_name ;; esac - display_alert "Checking out" - git checkout -f -q FETCH_HEAD - git clean -qdf + if [[ $? -ne 0 ]]; then + display_alert "Commit checkout not supported on this repository. Doing full clone." "" "wrn" + git pull --no-tags --all --no-summary + git checkout -f $ref_name + else + git checkout -f -q FETCH_HEAD + git clean -qdf + fi elif [[ -n $(git status -uno --porcelain --ignore-submodules=all) ]]; then # working directory is not clean if [[ $FORCE_CHECKOUT == yes ]]; then