diff --git a/Commands.md b/Commands.md index 6bfce20..228df36 100644 --- a/Commands.md +++ b/Commands.md @@ -442,7 +442,7 @@ removed. ## git release -Release commit with the given <tag>: +Release commit with the given <tag> and other options: ```bash $ git release 0.1.0 @@ -450,11 +450,11 @@ $ git release 0.1.0 Does the following: - - Executes _.git/hooks/pre-release.sh_ (if present) + - Executes _.git/hooks/pre-release.sh_ (if present), passing it the given tag and remain arguments - Commits changes (to changelog etc) with message "Release <tag>" - Tags with the given <tag> - Push the branch / tags - - Executes _.git/hooks/post-release.sh_ (if present) + - Executes _.git/hooks/post-release.sh_ (if present), passing it the given tag and remain arguments ## git rename-branch diff --git a/bin/git-release b/bin/git-release index 5836cdf..366f999 100755 --- a/bin/git-release +++ b/bin/git-release @@ -9,10 +9,11 @@ hook() { if test -f $hook; then echo "... $1" + shift if test -x $hook; then - $hook + $hook "$@" else - . $hook + . $hook "$@" fi fi } @@ -21,16 +22,16 @@ if test $# -gt 0; then version=$1 shift #remove version from arguments list remote='' - hook pre-release - echo "... releasing $version" + hook_args="$version" + # check for flags while test $# != 0 do case "$1" in - -c) git-changelog -t "$version" ;; + -c) need_changelog=true;; -r) remote=$2; shift ;; -m) msg=$2; shift ;; - --) shift; break;; + --) shift; hook_args="$hook_args $*"; break;; *) usage ;; esac shift @@ -38,11 +39,19 @@ if test $# -gt 0; then if [ -z "$msg" ]; then msg="Release ${version}" fi + + # shellcheck disable=SC2086 + hook pre-release $hook_args + echo "... releasing $version" + if [ "$need_changelog" = true ]; then + git-changelog -t "$version" + fi git commit -a -m "$msg" + # shellcheck disable=SC2086 git tag $version -a -m "$msg" \ && git push $remote \ && git push $remote --tags \ - && hook post-release \ + && hook post-release $hook_args \ && echo "... complete" else echo "tag required" 1>&2 && exit 1