Skip to content

Instantly share code, notes, and snippets.

@rolebi
Last active June 17, 2019 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolebi/a0eb1f783b7f3a5f21a631c8da1582dc to your computer and use it in GitHub Desktop.
Save rolebi/a0eb1f783b7f3a5f21a631c8da1582dc to your computer and use it in GitHub Desktop.
Travis continuous deployment fetch branch associated to current tag (to cleanup)
#!/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