Skip to content

Commit

Permalink
Merge pull request #944 from SimonTate/feature/sem-ver-prefix
Browse files Browse the repository at this point in the history
git-release: Add prefix to semver
  • Loading branch information
spacewander authored Apr 18, 2022
2 parents 02263ca + 613b909 commit 716459f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
14 changes: 10 additions & 4 deletions bin/git-release
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ if test $# -gt 0; then
semver=$2
shift
;;
--prefix)
test -z "$2" &&
exit_with_msg "prefix string required for --prefix option"
prefix="$2"
shift
;;
--no-empty-commit) no_empty_commit=true;;
--) shift; hook_args="$hook_args $*"; break;;
*) test -z "$version" && version=$1 ;;
Expand All @@ -69,7 +75,7 @@ if test $# -gt 0; then
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]+|[0-9])(.*) ]]; then
^$prefix([^0-9]*)([1-9][0-9]+|[0-9])\.([1-9][0-9]+|[0-9])\.([1-9][0-9]+|[0-9])(.*) ]]; then
echo "the latest tag doesn't match semver format requirement" 1>&2
exit 1
fi
Expand All @@ -86,9 +92,9 @@ if test $# -gt 0; then
(( ++version ))

case "$semver" in
major ) version="${BASH_REMATCH[1]}$version.0.0${BASH_REMATCH[5]}" ;;
minor ) version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}.$version.0${BASH_REMATCH[5]}" ;;
patch ) version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}.${BASH_REMATCH[3]}.$version${BASH_REMATCH[5]}" ;;
major ) version="$prefix${BASH_REMATCH[1]}$version.0.0${BASH_REMATCH[5]}" ;;
minor ) version="$prefix${BASH_REMATCH[1]}${BASH_REMATCH[2]}.$version.0${BASH_REMATCH[5]}" ;;
patch ) version="$prefix${BASH_REMATCH[1]}${BASH_REMATCH[2]}.${BASH_REMATCH[3]}.$version${BASH_REMATCH[5]}" ;;
esac
fi

Expand Down
1 change: 1 addition & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ _git-release() {
'-s[Create a signed and annotated tag.]' \
'-u[Create a tag, annotated and signed with the given key.]' \
'--semver[If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag.]' \
'--prefix[Add a prefix string to semver to allow more complex tags.]' \
'--no-empty-commit[Avoid creating empty commit if nothing could be committed.]' \
'--[The arguments listed after "--" separator will be passed to pre/post-release hook.]'
}
Expand Down
14 changes: 10 additions & 4 deletions man/git-release.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-RELEASE" "1" "April 2018" "" "Git Extras"
.TH "GIT\-RELEASE" "1" "April 2022" "" "Git Extras"
.
.SH "NAME"
\fBgit\-release\fR \- Commit, tag and push changes to the repository
.
.SH "SYNOPSIS"
\fBgit\-release\fR [<tagname> | \-\-semver <name>] [\-r <remote>] [\-m <commit info>] [\-\-no\-empty\-commit] [\-c] [\-s] [\-u <key-id>] [[\-\-] <hook arguments\.\.\.>]
\fBgit\-release\fR [<tagname> | \-\-semver <name>] [\-r <remote>] [\-m <commit info>] [\-\-no\-empty\-commit] [\-c] [\-s] [\-u <key\-id>] [\-\-prefix <tag prefix>] [[\-\-] <hook arguments\.\.\.>]
.
.SH "DESCRIPTION"
Commits changes with message "Release <tagname>" or custom commit information, tags with the given <tagname> and pushes the branch / tags\.
Expand All @@ -25,7 +25,7 @@ If \fB\.git/hook/pre\-release\fR or \fB\.git/hook/post\-release\fR exist, they w
\-\-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\.
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\. Use \fB\-\-prefix\fR if tag has a character before semver\.
.
.P
<tagname>
Expand All @@ -34,6 +34,12 @@ If the latest tag in your repo matches the semver format requirement, you could
The name of the newly created tag\. Also used in tag comment\.
.
.P
\-\-prefix <tag prefix>
.
.P
Use a prefix with a semver tag\. \fBgit release \-\-semver minor \-\-prefix r\fR would increment the latest tag r4\.4\.0 to r4\.5\.0\. This prefix can be any length, without spaces\.
.
.P
\-r <remote>
.
.P
Expand Down Expand Up @@ -64,7 +70,7 @@ Generates or populates the changelog with all commit message since the last tag\
Create a signed and annotated tag\.
.
.P
\-u <key ID>
\-u <key\-id>
.
.P
Create a tag, annotated and signed with the given key\.
Expand Down
15 changes: 10 additions & 5 deletions man/git-release.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/git-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ git-release(1) -- Commit, tag and push changes to the repository

## SYNOPSIS

`git-release` [&lt;tagname&gt; | --semver &lt;name&gt;] [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [--no-empty-commit] [-c] [-s] [-u &lt;key-id&gt;] [[--] &lt;hook arguments...&gt;]
`git-release` [&lt;tagname&gt; | --semver &lt;name&gt;] [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [--no-empty-commit] [-c] [-s] [-u &lt;key-id&gt;] [--prefix &lt;tag prefix&gt;] [[--] &lt;hook arguments...&gt;]

## DESCRIPTION

Expand All @@ -21,12 +21,17 @@ git-release(1) -- Commit, tag and push changes to the repository

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`.
`git release --semver minor` you will make a new release with tag `4.5.0`. Use `--prefix` if tag has a character before semver.

&lt;tagname&gt;

The name of the newly created tag. Also used in tag comment.

--prefix &lt;tag prefix&gt;

Use a prefix with a semver tag. `git release --semver minor --prefix r` would increment the latest tag r4.4.0 to r4.5.0. This prefix
can be any length, without spaces.

-r &lt;remote&gt;

The "remote" repository that is destination of a push operation: it is passed to git push.
Expand Down

0 comments on commit 716459f

Please sign in to comment.