Last active
June 17, 2019 06:47
-
-
Save rolebi/a0eb1f783b7f3a5f21a631c8da1582dc to your computer and use it in GitHub Desktop.
Travis continuous deployment fetch branch associated to current tag (to cleanup)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REFERENCE="$1" | |
if [ -z "$REFERENCE" ] | |
then | |
echo "usage: $0 reference" 1>&2 | |
exit 1 | |
fi | |
# Fix for repository that have been cloned with --branch option (aka during travis build) | |
OLD_FETCH_CONFIG="`git config remote.origin.fetch`" | |
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" 1>/dev/null | |
git fetch origin -q | |
BRANCHES=`git branch -a --contains "$REFERENCE" 2>/dev/null | grep -v '(' | sed 's|^.*/||g;s|^\s*\**\s*||;s|\s*$||' | sort -u` | |
git config remote.origin.fetch "$OLD_FETCH_CONFIG" 1>/dev/null | |
if [ -z "$BRANCHES" ] | |
then | |
echo "No branch found for reference '$REFERENCE' reference" 1>&2 | |
exit 0 | |
fi | |
for BRANCH in preprod uat integration master | |
do | |
if [ "`echo "$BRANCHES" | grep "$BRANCH"`" == "$BRANCH" ] | |
then | |
echo "$BRANCH" | |
exit 0 | |
fi | |
done | |
if [ -z "$BRANCHES" ] | |
then | |
echo "No branch found for reference '$REFERENCE' reference" 1>&2 | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment