|
| 1 | +#!/usr/bin/bash |
| 2 | +require_clean_work_tree () { |
| 3 | + # Update the index |
| 4 | + git update-index -q --ignore-submodules --refresh |
| 5 | + err=0 |
| 6 | + |
| 7 | + # Disallow unstaged changes in the working tree |
| 8 | + if ! git diff-files --quiet --ignore-submodules -- |
| 9 | + then |
| 10 | + echo >&2 "cannot $1: you have unstaged changes." |
| 11 | + git diff-files --name-status -r --ignore-submodules -- >&2 |
| 12 | + err=1 |
| 13 | + fi |
| 14 | + |
| 15 | + # Disallow uncommitted changes in the index |
| 16 | + if ! git diff-index --cached --quiet HEAD --ignore-submodules -- |
| 17 | + then |
| 18 | + echo >&2 "cannot $1: your index contains uncommitted changes." |
| 19 | + git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2 |
| 20 | + err=1 |
| 21 | + fi |
| 22 | + |
| 23 | + if git diff-index --quiet HEAD -- |
| 24 | + then |
| 25 | + echo >&2 "cannot $1: your index contains untracked files." |
| 26 | + # err=1 |
| 27 | + fi |
| 28 | + |
| 29 | + if [ $err = 1 ] |
| 30 | + then |
| 31 | + echo >&2 "Please commit or stash them." |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +} |
| 35 | + |
| 36 | +revert_release () { |
| 37 | + git reset HEAD~1 --hard |
| 38 | + git tag --delete ${release} |
| 39 | + echo "Reverted release" |
| 40 | + exit 0 |
| 41 | +} |
| 42 | + |
| 43 | +trap 'revert_release' SIGINT |
| 44 | + |
| 45 | +if [[ $# -ne 1 ]]; then |
| 46 | + echo 'create-new-release [new version]' |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +require_clean_work_tree "create a release" |
| 51 | + |
| 52 | +release=$1 |
| 53 | +lastRelease=$(git tag | sort -V | tail -1) |
| 54 | + |
| 55 | +echo "Creating a new release '${release}'" |
| 56 | +sed -i "s/${lastRelease}/${release}/g" README.md |
| 57 | +echo "Updated README.md" |
| 58 | +git add README.md |
| 59 | +git commit -m ${release} |
| 60 | +git tag ${release} |
| 61 | +echo "Created a tag & a commit" |
| 62 | + |
| 63 | +echo "Release is ready for pushing (press any to push)" |
| 64 | +read -n 1 -s -r |
| 65 | +git push --all |
| 66 | + |
| 67 | +echo "Done" |
0 commit comments