cloudfoundry/stratos

View on GitHub
deploy/ci/scripts/git-resource-check

Summary

Maintainability
Test Coverage
#!/bin/bash
# vim: set ft=sh

set -e

exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging

source $(dirname $0)/common.sh

# for jq
PATH=/usr/local/bin:$PATH

payload=$TMPDIR/git-resource-request

cat > $payload <&0

load_pubkey $payload
configure_https_tunnel $payload
configure_git_ssl_verification $payload
configure_credentials $payload

uri=$(jq -r '.source.uri // ""' < $payload)
branch=$(jq -r '.source.branch // ""' < $payload)
tag_filter=$(jq -r '.source.tag_filter // ""' < $payload)
git_config_payload=$(jq -r '.source.git_config // []' < $payload)

configure_git_global "${git_config_payload}"

destination=$TMPDIR/git-resource-repo-cache

if [ -d $destination ]; then
  cd $destination
  git fetch --prune-tags --tags
  git reset --hard origin/$branch
else
  git clone --single-branch $uri --branch $branch $destination
  cd $destination
fi

echo "Tag filter: $tag_filter"
git checkout $tag_filter

COMMIT=$(git rev-parse HEAD)

echo $COMMIT

if [ $? -ne 0 ]; then
  echo "[]" >&3
else
  echo "[{ \"ref\": \"$COMMIT\" }]" >&3
fi