Skip to content

Commit 716459f

Browse files
authored
Merge pull request #944 from SimonTate/feature/sem-ver-prefix
git-release: Add prefix to semver
2 parents 02263ca + 613b909 commit 716459f

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

bin/git-release

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ if test $# -gt 0; then
5151
semver=$2
5252
shift
5353
;;
54+
--prefix)
55+
test -z "$2" &&
56+
exit_with_msg "prefix string required for --prefix option"
57+
prefix="$2"
58+
shift
59+
;;
5460
--no-empty-commit) no_empty_commit=true;;
5561
--) shift; hook_args="$hook_args $*"; break;;
5662
*) test -z "$version" && version=$1 ;;
@@ -69,7 +75,7 @@ if test $# -gt 0; then
6975
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
7076

7177
if [[ ! "$latest_tag" =~ \
72-
^([^0-9]*)([1-9][0-9]+|[0-9])\.([1-9][0-9]+|[0-9])\.([1-9][0-9]+|[0-9])(.*) ]]; then
78+
^$prefix([^0-9]*)([1-9][0-9]+|[0-9])\.([1-9][0-9]+|[0-9])\.([1-9][0-9]+|[0-9])(.*) ]]; then
7379
echo "the latest tag doesn't match semver format requirement" 1>&2
7480
exit 1
7581
fi
@@ -86,9 +92,9 @@ if test $# -gt 0; then
8692
(( ++version ))
8793

8894
case "$semver" in
89-
major ) version="${BASH_REMATCH[1]}$version.0.0${BASH_REMATCH[5]}" ;;
90-
minor ) version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}.$version.0${BASH_REMATCH[5]}" ;;
91-
patch ) version="${BASH_REMATCH[1]}${BASH_REMATCH[2]}.${BASH_REMATCH[3]}.$version${BASH_REMATCH[5]}" ;;
95+
major ) version="$prefix${BASH_REMATCH[1]}$version.0.0${BASH_REMATCH[5]}" ;;
96+
minor ) version="$prefix${BASH_REMATCH[1]}${BASH_REMATCH[2]}.$version.0${BASH_REMATCH[5]}" ;;
97+
patch ) version="$prefix${BASH_REMATCH[1]}${BASH_REMATCH[2]}.${BASH_REMATCH[3]}.$version${BASH_REMATCH[5]}" ;;
9298
esac
9399
fi
94100

etc/git-extras-completion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ _git-release() {
297297
'-s[Create a signed and annotated tag.]' \
298298
'-u[Create a tag, annotated and signed with the given key.]' \
299299
'--semver[If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag.]' \
300+
'--prefix[Add a prefix string to semver to allow more complex tags.]' \
300301
'--no-empty-commit[Avoid creating empty commit if nothing could be committed.]' \
301302
'--[The arguments listed after "--" separator will be passed to pre/post-release hook.]'
302303
}

man/git-release.1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIT\-RELEASE" "1" "April 2018" "" "Git Extras"
4+
.TH "GIT\-RELEASE" "1" "April 2022" "" "Git Extras"
55
.
66
.SH "NAME"
77
\fBgit\-release\fR \- Commit, tag and push changes to the repository
88
.
99
.SH "SYNOPSIS"
10-
\fBgit\-release\fR [<tagname> | \-\-semver <name>] [\-r <remote>] [\-m <commit info>] [\-\-no\-empty\-commit] [\-c] [\-s] [\-u <key-id>] [[\-\-] <hook arguments\.\.\.>]
10+
\fBgit\-release\fR [<tagname> | \-\-semver <name>] [\-r <remote>] [\-m <commit info>] [\-\-no\-empty\-commit] [\-c] [\-s] [\-u <key\-id>] [\-\-prefix <tag prefix>] [[\-\-] <hook arguments\.\.\.>]
1111
.
1212
.SH "DESCRIPTION"
1313
Commits changes with message "Release <tagname>" or custom commit information, tags with the given <tagname> and pushes the branch / tags\.
@@ -25,7 +25,7 @@ If \fB\.git/hook/pre\-release\fR or \fB\.git/hook/post\-release\fR exist, they w
2525
\-\-semver <name>
2626
.
2727
.P
28-
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\.
28+
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\.
2929
.
3030
.P
3131
<tagname>
@@ -34,6 +34,12 @@ If the latest tag in your repo matches the semver format requirement, you could
3434
The name of the newly created tag\. Also used in tag comment\.
3535
.
3636
.P
37+
\-\-prefix <tag prefix>
38+
.
39+
.P
40+
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\.
41+
.
42+
.P
3743
\-r <remote>
3844
.
3945
.P
@@ -64,7 +70,7 @@ Generates or populates the changelog with all commit message since the last tag\
6470
Create a signed and annotated tag\.
6571
.
6672
.P
67-
\-u <key ID>
73+
\-u <key\-id>
6874
.
6975
.P
7076
Create a tag, annotated and signed with the given key\.

man/git-release.html

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-release.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ git-release(1) -- Commit, tag and push changes to the repository
33

44
## SYNOPSIS
55

6-
`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;]
6+
`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;]
77

88
## DESCRIPTION
99

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

2222
If the latest tag in your repo matches the semver format requirement, you could increase part of it as the new release tag
2323
with this option. The name must be one of the `major`, `minor`, `patch`. For example, assumed the latest tag is `4.4.0`, with
24-
`git release --semver minor` you will make a new release with tag `4.5.0`.
24+
`git release --semver minor` you will make a new release with tag `4.5.0`. Use `--prefix` if tag has a character before semver.
2525

2626
&lt;tagname&gt;
2727

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

30+
--prefix &lt;tag prefix&gt;
31+
32+
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
33+
can be any length, without spaces.
34+
3035
-r &lt;remote&gt;
3136

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

0 commit comments

Comments
 (0)