Skip to content

Commit f9db6fb

Browse files
authored
Merge pull request #346 from lsst/tickets/DM-53120
Add git clone fallback for repos.yaml
2 parents 5f55760 + 56faa14 commit f9db6fb

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

bin/utils.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,30 @@ fetch_repos.yaml() {
167167
local repo=${3:-$REPOSFILE_REPO}
168168

169169
local baseurl="https://raw.githubusercontent.com/${repo}/${ref}"
170+
local output_dir
171+
output_dir=$(dirname "$output_file")
170172

171-
$CURL "${CURL_OPTS[@]}" \
172-
-L \
173-
"${baseurl}/etc/repos.yaml" \
174-
-o "$output_file"
173+
if $CURL "${CURL_OPTS[@]}" -f -L "${baseurl}/etc/repos.yaml" -o "$output_file"; then
174+
return 0
175+
fi
176+
177+
echo "HTTPS download failed; falling back to git clone of ${repo}@${ref}"
178+
179+
(
180+
cd "$output_dir" || exit 1
181+
182+
# Clone into same directory but with unique PID to only copy repos.yaml
183+
local clone_dir=".repos_clone_$$"
184+
185+
if git clone --depth 1 --branch "$ref" "https://github.com/${repo}.git" "$clone_dir"; then
186+
if [ -f "${clone_dir}/etc/repos.yaml" ]; then
187+
cp "${clone_dir}/etc/repos.yaml" "$output_file"
188+
echo "repos.yaml successfully retrieved via git clone"
189+
fi
190+
rm -rf "$clone_dir"
191+
else
192+
echo "git clone fallback failed for ${repo}@${ref}" >&2
193+
return 1
194+
fi
195+
)
175196
}

0 commit comments

Comments
 (0)