@@ -59,25 +59,74 @@ log "Ref: $SQLITE_REF"
5959log " Out: $OUT_DIR "
6060log " Src dir: $SRC_DIR "
6161
62+ resolve_and_fetch_ref () {
63+ local repo_dir=" $1 "
64+ local ref=" $2 "
65+
66+ # Try as provided (works for explicit refs and SHAs)
67+ if git -C " $repo_dir " fetch --depth 1 origin " $ref " ; then
68+ return 0
69+ fi
70+
71+ # Try as branch name
72+ if git -C " $repo_dir " fetch --depth 1 origin " refs/heads/$ref " ; then
73+ return 0
74+ fi
75+
76+ # Try as tag name
77+ if git -C " $repo_dir " fetch --depth 1 origin " refs/tags/$ref " ; then
78+ return 0
79+ fi
80+
81+ # SQLite release tags are commonly prefixed with version-
82+ if git -C " $repo_dir " fetch --depth 1 origin " refs/tags/version-$ref " ; then
83+ return 0
84+ fi
85+
86+ # Last attempt without shallow for commit SHAs and uncommon refs
87+ if git -C " $repo_dir " fetch origin " $ref " ; then
88+ return 0
89+ fi
90+
91+ if git -C " $repo_dir " fetch origin " refs/heads/$ref " ; then
92+ return 0
93+ fi
94+
95+ if git -C " $repo_dir " fetch origin " refs/tags/$ref " ; then
96+ return 0
97+ fi
98+
99+ if git -C " $repo_dir " fetch origin " refs/tags/version-$ref " ; then
100+ return 0
101+ fi
102+
103+ return 1
104+ }
105+
62106# prepare source dir: clone shallow or fetch+reset if exists
63107if [ -d " $SRC_DIR /.git" ]; then
64108 log " Repository already exists, fetching updates..."
65- git -C " $SRC_DIR " fetch --depth 1 origin " $SQLITE_REF " || git -C " $SRC_DIR " fetch --unshallow || true
66- git -C " $SRC_DIR " checkout --detach FETCH_HEAD || git -C " $SRC_DIR " checkout " $SQLITE_REF " || git -C " $SRC_DIR " reset --hard origin/" $SQLITE_REF "
109+ if resolve_and_fetch_ref " $SRC_DIR " " $SQLITE_REF " ; then
110+ git -C " $SRC_DIR " checkout --detach FETCH_HEAD
111+ else
112+ log " Failed to fetch ref from existing repository, attempting full fetch..."
113+ git -C " $SRC_DIR " fetch --all --tags
114+ git -C " $SRC_DIR " checkout --detach " $SQLITE_REF " || git -C " $SRC_DIR " checkout --detach " refs/tags/$SQLITE_REF " || git -C " $SRC_DIR " checkout --detach " refs/tags/version-$SQLITE_REF " || git -C " $SRC_DIR " checkout --detach " origin/$SQLITE_REF "
115+ fi
67116else
68117 log " Cloning repository..."
69118 rm -rf " $SRC_DIR "
70119 mkdir -p " $SRC_DIR "
71120 git -C " $SRC_DIR " init
72121 git -C " $SRC_DIR " remote add origin " $SQLITE_REPO "
73122 log " Fetching ref: $SQLITE_REF "
74- if git -C " $SRC_DIR " fetch --depth 1 origin " $SQLITE_REF " ; then
123+ if resolve_and_fetch_ref " $SRC_DIR " " $SQLITE_REF " ; then
75124 git -C " $SRC_DIR " checkout --detach FETCH_HEAD
76125 else
77126 log " Failed to fetch shallow ref, trying full clone..."
78127 rm -rf " $SRC_DIR "
79128 git clone " $SQLITE_REPO " " $SRC_DIR "
80- git -C " $SRC_DIR " checkout " $SQLITE_REF "
129+ git -C " $SRC_DIR " checkout --detach " $SQLITE_REF " || git -C " $SRC_DIR " checkout --detach " refs/tags/ $SQLITE_REF " || git -C " $SRC_DIR " checkout --detach " refs/tags/version- $SQLITE_REF " || git -C " $SRC_DIR " checkout --detach " origin/ $SQLITE_REF "
81130 fi
82131fi
83132
0 commit comments