better commit hash handling
This commit is contained in:
+26
-6
@@ -44,13 +44,33 @@ if [ "$COMMIT" == "$(git rev-parse --short HEAD)" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
check_remote_commit_exists() {
|
||||
# Usage: check_remote_commit_exists <repo-url> <commit-sha>
|
||||
local url="$1"
|
||||
local commit="$2"
|
||||
|
||||
# Create a temporary directory for a shallow fetch
|
||||
local tmpdir
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' RETURN # auto-cleanup on function exit
|
||||
|
||||
git -C "$tmpdir" init -q
|
||||
git -C "$tmpdir" remote add origin "$url"
|
||||
|
||||
if git -C "$tmpdir" fetch --quiet --depth=1 origin "$commit" 2>/dev/null; then
|
||||
echo "✅ Commit $commit exists on remote."
|
||||
return 0
|
||||
else
|
||||
echo "❌ ERROR: Commit $commit not found on remote."
|
||||
echo "Refs currently visible on remote:"
|
||||
git ls-remote --heads --tags "$url"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# check if the commit has been pushed
|
||||
REMOTE_COMMIT=$(git ls-remote https://github.com/jkiesele/minicalosim | grep $COMMIT)
|
||||
if [ -z "$REMOTE_COMMIT" ]; then
|
||||
echo "ERROR: Commit $COMMIT not found in remote repository."
|
||||
echo only found commits:
|
||||
git ls-remote https://github.com/jkiesele/minicalosim
|
||||
exit 1
|
||||
if ! check_remote_commit_exists https://github.com/jkiesele/minicalosim $COMMIT; then
|
||||
echo "ERROR: Commit $COMMIT not found in remote repository."
|
||||
fi
|
||||
|
||||
# check if no-cache is given as second argument
|
||||
|
||||
Reference in New Issue
Block a user