Merge pull request #686 from spacewander/add_semver

git-release: add --semver option
This commit is contained in:
hemanth.hm 2017-12-10 12:34:05 +05:30 committed by GitHub
commit 17fce79d3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 12 deletions

View file

@ -458,6 +458,13 @@ Release commit with the given <tag> and other options:
$ git release 0.1.0
```
If you are using [semver](https://semver.org) in your project, you could also use the command below:
(Run `git help release` for more information)
```bash
$ git release --semver major/minor/patch
```
Does the following:
- Executes _.git/hooks/pre-release.sh_ (if present), passing it the given tag and remain arguments

View file

@ -25,10 +25,7 @@ exit_with_msg() {
}
if test $# -gt 0; then
version=$1
shift #remove version from arguments list
remote=''
hook_args="$version"
# check for flags
while test $# != 0
@ -37,12 +34,51 @@ if test $# -gt 0; then
-c) need_changelog=true;;
-r) remote=$2; shift ;;
-m) msg=$2; shift ;;
--semver) semver=$2; shift ;;
--) shift; hook_args="$hook_args $*"; break;;
*) test -z "$version" && version=$1 ;;
esac
shift
done
if [ -n "$semver" ]; then
if [ -z "$(git tag)" ]; then
echo "there is no tag in the git repo" 1>&2
exit 1
fi
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
if [[ ! "$latest_tag" =~ \
([0-9]|[1-9][0-9]+)\.([0-9]|[1-9][0-9]+)\.([0-9]|[1-9][0-9]+)(.*) ]]; then
echo "the latest tag doesn't match semver format requirement" 1>&2
exit 1
fi
case "$semver" in
major ) version="${BASH_REMATCH[1]}" ;;
minor ) version="${BASH_REMATCH[2]}" ;;
patch ) version="${BASH_REMATCH[3]}" ;;
* ) echo "invalid semver argument given: $semver" 1>&2
exit 1
;;
esac
(( ++version ))
case "$semver" in
major ) version="$version.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}${BASH_REMATCH[4]}" ;;
minor ) version="${BASH_REMATCH[1]}.$version.${BASH_REMATCH[3]}${BASH_REMATCH[4]}" ;;
patch ) version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$version${BASH_REMATCH[4]}" ;;
esac
fi
hook_args="$version"
if [ -z "$msg" ]; then
msg="Release ${version}"
msg="Release ${version}"
fi
# shellcheck disable=SC2086
@ -50,7 +86,7 @@ if test $# -gt 0; then
|| exit_with_msg "pre-release hook failed! Cancelling release."
echo "... releasing $version"
if [ "$need_changelog" = true ]; then
git-changelog -t "$version"
git-changelog -t "$version"
fi
git commit -a -m "$msg"
# shellcheck disable=SC2086

View file

@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-RELEASE" "1" "May 2017" "" ""
.TH "GIT\-RELEASE" "1" "December 2017" "" ""
.
.SH "NAME"
\fBgit\-release\fR \- Commit, tag and push changes to the repository
.
.SH "SYNOPSIS"
\fBgit\-release\fR <tagname> [\-r <remote>] [\-m <commit info>] [\-c] [[\-\-] <hook arguments\.\.\.>]
\fBgit\-release\fR [<tagname> | \-\-semver <name>] [\-r <remote>] [\-m <commit info>] [\-c] [[\-\-] <hook arguments\.\.\.>]
.
.SH "DESCRIPTION"
Commits changes with message "Release <tagname>" or custom commit information, tags with the given <tagname> and pushes the branch / tags\.
@ -19,6 +19,12 @@ Optionally it generates a changelog (see git\-changelog) and a remote can be def
If \fB\.git/hook/pre\-release\fR or \fB\.git/hook/post\-release\fR exist, they will be triggered with \fBtagname\fR and extra hook arguments before/after the release\.
.
.SH "OPTIONS"
\-\-semver <name>
.
.P
If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag with this option\. The name must be one of the \fBmajor\fR, \fBminor\fR, \fBpatch\fR\. For example, assumed the latest tag is \fB4\.4\.0\fR, with \fBgit release \-\-semver minor\fR you will make a new release with tag \fB4\.5\.0\fR\.
.
.P
<tagname>
.
.P

View file

@ -76,7 +76,7 @@
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-release</code> &lt;tagname&gt; [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [-c] [[--] &lt;hook arguments...&gt;]</p>
<p><code>git-release</code> [&lt;tagname&gt; | --semver &lt;name&gt;] [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [-c] [[--] &lt;hook arguments...&gt;]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
@ -88,6 +88,12 @@
<h2 id="OPTIONS">OPTIONS</h2>
<p> --semver &lt;name&gt;</p>
<p> If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag
with this option. The name must be one of the <code>major</code>, <code>minor</code>, <code>patch</code>. For example, assumed the latest tag is <code>4.4.0</code>, with
<code>git release --semver minor</code> you will make a new release with tag <code>4.5.0</code>.</p>
<p> &lt;tagname&gt;</p>
<p> The name of the newly created tag. Also used in tag comment.</p>
@ -135,8 +141,8 @@ populate changelog, and push to specific remote.</p>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Tj Holowaychuk &lt;<a href="&#x6d;&#97;&#105;&#108;&#116;&#x6f;&#x3a;&#116;&#106;&#64;&#x76;&#105;&#115;&#x69;&#111;&#110;&#45;&#109;&#x65;&#100;&#105;&#97;&#46;&#x63;&#97;" data-bare-link="true">&#116;&#x6a;&#64;&#118;&#x69;&#x73;&#x69;&#x6f;&#x6e;&#x2d;&#109;&#x65;&#x64;&#105;&#x61;&#x2e;&#x63;&#x61;</a>&gt;
Extended by David Hartmann &lt;<a href="&#x6d;&#97;&#x69;&#108;&#x74;&#x6f;&#x3a;&#x64;&#x68;&#x40;&#x74;&#115;&#108;&#x2e;&#x69;&#111;" data-bare-link="true">&#x64;&#104;&#64;&#116;&#115;&#x6c;&#46;&#105;&#111;</a>&gt;</p>
<p>Written by Tj Holowaychuk &lt;<a href="&#x6d;&#x61;&#105;&#x6c;&#x74;&#x6f;&#x3a;&#x74;&#106;&#64;&#118;&#105;&#x73;&#105;&#111;&#x6e;&#45;&#x6d;&#x65;&#100;&#105;&#97;&#x2e;&#99;&#x61;" data-bare-link="true">&#116;&#x6a;&#64;&#x76;&#105;&#115;&#105;&#x6f;&#110;&#x2d;&#109;&#x65;&#x64;&#x69;&#97;&#x2e;&#99;&#97;</a>&gt;
Extended by David Hartmann &lt;<a href="&#109;&#97;&#x69;&#108;&#116;&#111;&#x3a;&#x64;&#104;&#64;&#116;&#115;&#x6c;&#46;&#105;&#x6f;" data-bare-link="true">&#x64;&#104;&#x40;&#116;&#x73;&#108;&#x2e;&#x69;&#x6f;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -149,7 +155,7 @@ Extended by David Hartmann &lt;<a href="&#x6d;&#97;&#x69;&#108;&#x74;&#x6f;&#x3a
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>May 2017</li>
<li class='tc'>December 2017</li>
<li class='tr'>git-release(1)</li>
</ol>

View file

@ -3,7 +3,7 @@ git-release(1) -- Commit, tag and push changes to the repository
## SYNOPSIS
`git-release` &lt;tagname&gt; [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [-c] [[--] &lt;hook arguments...&gt;]
`git-release` [&lt;tagname&gt; | --semver &lt;name&gt;] [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [-c] [[--] &lt;hook arguments...&gt;]
## DESCRIPTION
@ -15,6 +15,12 @@ git-release(1) -- Commit, tag and push changes to the repository
## OPTIONS
--semver &lt;name&gt;
If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag
with this option. The name must be one of the `major`, `minor`, `patch`. For example, assumed the latest tag is `4.4.0`, with
`git release --semver minor` you will make a new release with tag `4.5.0`.
&lt;tagname&gt;
The name of the newly created tag. Also used in tag comment.