mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Merge pull request #686 from spacewander/add_semver
git-release: add --semver option
This commit is contained in:
commit
17fce79d3c
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-release</code> <tagname> [-r <remote>] [-m <commit info>] [-c] [[--] <hook arguments...>]</p>
|
||||
<p><code>git-release</code> [<tagname> | --semver <name>] [-r <remote>] [-m <commit info>] [-c] [[--] <hook arguments...>]</p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
|
|
@ -88,6 +88,12 @@
|
|||
|
||||
<h2 id="OPTIONS">OPTIONS</h2>
|
||||
|
||||
<p> --semver <name></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> <tagname></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 <<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>>
|
||||
Extended by David Hartmann <<a href="mailto:dh@tsl.io" data-bare-link="true">dh@tsl.io</a>></p>
|
||||
<p>Written by Tj Holowaychuk <<a href="mailto:tj@vision-media.ca" data-bare-link="true">tj@vision-media.ca</a>>
|
||||
Extended by David Hartmann <<a href="mailto:dh@tsl.io" data-bare-link="true">dh@tsl.io</a>></p>
|
||||
|
||||
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
|
||||
|
||||
|
|
@ -149,7 +155,7 @@ Extended by David Hartmann <<a href="mailto:
|
|||
|
||||
<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>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ git-release(1) -- Commit, tag and push changes to the repository
|
|||
|
||||
## SYNOPSIS
|
||||
|
||||
`git-release` <tagname> [-r <remote>] [-m <commit info>] [-c] [[--] <hook arguments...>]
|
||||
`git-release` [<tagname> | --semver <name>] [-r <remote>] [-m <commit info>] [-c] [[--] <hook arguments...>]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
|
|
@ -15,6 +15,12 @@ git-release(1) -- Commit, tag and push changes to the repository
|
|||
|
||||
## OPTIONS
|
||||
|
||||
--semver <name>
|
||||
|
||||
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`.
|
||||
|
||||
<tagname>
|
||||
|
||||
The name of the newly created tag. Also used in tag comment.
|
||||
|
|
|
|||
Loading…
Reference in a new issue