File indexing completed on 2026-08-12 08:24:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 set -e
0015
0016
0017 if [ $
0018 cat >&2 << 'USAGE'
0019 Usage: resolve_git_ref <repo> <ref>
0020
0021 Resolves a git reference (branch, tag, or commit SHA) to a full commit SHA.
0022
0023 Arguments:
0024 repo Git repository, either:
0025 - org/repo format (e.g., eic/edm4eic)
0026 - Full URL (e.g., https://github.com/eic/edm4eic.git)
0027 ref Git reference: branch name, tag name, or commit SHA
0028
0029 Examples:
0030
0031 resolve_git_ref eic/edm4eic main
0032
0033
0034 resolve_git_ref https://github.com/eic/epic.git v24.11.0
0035
0036
0037 resolve_git_ref eic/eicrecon abc123def456...
0038
0039 Exit codes:
0040 0 - Success (SHA printed to stdout)
0041 1 - Error (message printed to stderr)
0042 USAGE
0043 exit 1
0044 fi
0045
0046
0047 if [ $
0048 echo "Error: Expected 2 arguments, got $#" >&2
0049 echo "Run 'resolve_git_ref --help' for usage" >&2
0050 exit 1
0051 fi
0052
0053 case "${1}" in
0054 http*)
0055 repo_url="${1}"
0056 ;;
0057 *)
0058 repo_url="https://github.com/${1}.git"
0059 ;;
0060 esac
0061 ref="${2}"
0062
0063
0064 if [ -z "${ref}" ]; then
0065 echo "Error: ref argument is empty" >&2
0066 exit 1
0067 fi
0068
0069
0070
0071
0072 case "${ref}" in
0073 *[!0-9a-f]*)
0074
0075 ;;
0076 *)
0077
0078 ref_len=${
0079 if [ "${ref_len}" -ge 7 ] && [ "${ref_len}" -le 40 ]; then
0080 echo "${ref}"
0081 exit 0
0082 fi
0083 ;;
0084 esac
0085
0086
0087 sha=$(git ls-remote "${repo_url}" "refs/heads/${ref}" 2>/dev/null | cut -f1)
0088 if [ -n "${sha}" ]; then
0089 echo "${sha}"
0090 exit 0
0091 fi
0092
0093
0094 sha=$(git ls-remote "${repo_url}" "refs/tags/${ref}" 2>/dev/null | cut -f1)
0095 if [ -n "${sha}" ]; then
0096 echo "${sha}"
0097 exit 0
0098 fi
0099
0100
0101 sha=$(git ls-remote "${repo_url}" "refs/tags/${ref}^{}" 2>/dev/null | cut -f1)
0102 if [ -n "${sha}" ]; then
0103 echo "${sha}"
0104 exit 0
0105 fi
0106
0107
0108 echo "Error: Unable to resolve ref '${ref}' in repository '${repo_url}'" >&2
0109 echo "Ref must be a valid branch name, tag name, or commit SHA" >&2
0110 exit 1