Skip to content

Commit adca367

Browse files
committed
refactor(git): reuse _git_sources_pinned_sha1 helper in fetch_from_repo
fetch_from_repo() carried its own copy of the pinned-SHA lookup from memoized_git_ref_to_info(), with the same shell-interpolated jq program (source/branch concatenated into the filter text). Replace it with the shared _git_sources_pinned_sha1 helper added earlier in this branch, which passes values through jq --arg, and validate the pinned SHA before overriding fetched_revision so a malformed pin fails loudly instead of silently — matching the branch path in git-ref2info.sh. Pure code cleanup: removes the last duplicated jq-injection of this lookup. Assisted-by: Claude:claude-opus-4.8
1 parent 6ea7313 commit adca367

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/functions/general/git.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,14 @@ function fetch_from_repo() {
252252
esac
253253
fi
254254

255-
if [[ -f "${SRC}"/config/sources/git_sources.json && $ref_type == "branch" ]]; then
256-
cached_revision=$(jq --raw-output '.[] | select(.source == "'$url'" and .branch == "'$ref_name'") |.sha1' "${SRC}"/config/sources/git_sources.json)
257-
[[ -z "${cached_revision}" ]] || fetched_revision=${cached_revision}
255+
if [[ "${ref_type}" == "branch" ]]; then
256+
declare cached_revision
257+
cached_revision="$(_git_sources_pinned_sha1 "${url}" "${ref_name}")"
258+
if [[ "${cached_revision}" =~ ^[0-9a-f]{40}$ ]]; then
259+
fetched_revision="${cached_revision}"
260+
elif [[ -n "${cached_revision}" ]]; then
261+
exit_with_error "Invalid pinned SHA1 '${cached_revision}' for '${url}' '${ref_name}' in config/sources/git_sources.json"
262+
fi
258263
fi
259264

260265
if [[ "${do_checkout:-"yes"}" == "yes" ]]; then
@@ -279,8 +284,8 @@ function fetch_from_repo() {
279284
while read -r key path; do
280285
# key is like: submodule.libfoo.path
281286
# extract "libfoo" from "submodule.libfoo.path"
282-
local name=${key#submodule.} # -> libfoo.path
283-
name=${name%.path} # -> libfoo
287+
local name=${key#submodule.} # -> libfoo.path
288+
name=${name%.path} # -> libfoo
284289

285290
cd "${git_work_dir}" || exit
286291

0 commit comments

Comments
 (0)