Last active
May 22, 2018 10:38
-
-
Save damiankloip/a6b2f04670f23c424c288112d8761637 to your computer and use it in GitHub Desktop.
git next-tag script
This file contains hidden or 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/sh | |
if ! [ -x "$(command -v semver)" ]; then | |
echo 'Error: semver is not installed. Install using `npm install --global --save semver`' >&2 | |
exit 1 | |
fi | |
# Get tags ordered correctly, and take the last one. | |
last="$(git tag --sort=v:refname | tail -n1)" | |
if [ -z "$last" ]; then | |
echo "No last tag found" | |
exit 0 | |
fi | |
# $1 can be major, minor, or patch. Defaults to patch. | |
next=$(semver -i "${1-patch}" "$last") | |
echo "Last tag: $last" | |
echo "Next tag: $next" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If this script is executable and included in your
PATH
, you will be able to run this likegit next-tag
.The version increment defaults to 'patch', but can pass 'major', 'minor', or 'patch', for example:
git next-tag minor