Skip to content

feat: Add check for existing tag and bad branch #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions autotag
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# https://github.com/MichaelCurrin/auto-tag/blob/master/LICENSE

FALLBACK_TAG='v0.0.0'
ALLOWED_BRANCHES='master|main|develop|dev|edge'

USAGE='USAGE: autotag LEVEL [-p] [-h]'
HELP="$USAGE
Expand All @@ -22,6 +23,26 @@ Flags:
-p --preview: Do a dry run to show the new tag label only, without creating it.
"

checks() {
if git describe --tags --exact-match &>/dev/null; then
echo '🛑 Commit is already tagged - aborting.'
exit 1
fi

local BRANCH=$(git branch --show-current)

if [[ -z "$BRANCH" ]]; then
echo '🛑 You appear to be checked out on a commit or tag. Please check out a branch.'
exit 1
fi

if [[ ! "$BRANCH" =~ "$ALLOWED_BRANCHES" ]]; then
echo "🛑 You appear to be on a feature branch. Please check out your repo's default branch"
echo "Allowed branches are: $ALLOWED_BRANCHES"
exit 1
fi
}

if [[ "$#" -eq 0 ]] || [[ "$1" == '-h' ]] || [[ "$1" == '--help' ]]; then
echo "$HELP"
exit 1
Expand All @@ -41,6 +62,8 @@ else
PREVIEW='false'
fi

checks

echo '🚛 Fetching tags...'

git fetch --tags
Expand Down