git-release: add --no-empty-commit for empty commit hater

This commit is contained in:
spacewander 2018-02-10 14:02:10 +08:00 committed by 罗泽轩
parent 8714ac4aa1
commit de364cfac1
4 changed files with 36 additions and 8 deletions

View file

@ -35,6 +35,7 @@ if test $# -gt 0; then
-r) remote=$2; shift ;;
-m) msg=$2; shift ;;
--semver) semver=$2; shift ;;
--no-empty-commit) no_empty_commit=true;;
--) shift; hook_args="$hook_args $*"; break;;
*) test -z "$version" && version=$1 ;;
esac
@ -88,7 +89,13 @@ if test $# -gt 0; then
if [ "$need_changelog" = true ]; then
git-changelog -t "$version"
fi
git commit -a -m "$msg" --allow-empty
if [ "$no_empty_commit" = true ]; then
git commit -a -m "$msg" || true
else
git commit -a -m "$msg" --allow-empty
fi
# shellcheck disable=SC2086
git tag $version -a -m "$msg" \
&& git push $remote --tags \

View file

@ -1,18 +1,21 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-RELEASE" "1" "December 2017" "" ""
.TH "GIT\-RELEASE" "1" "February 2018" "" ""
.
.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>] [\-c] [[\-\-] <hook arguments\.\.\.>]
\fBgit\-release\fR [<tagname> | \-\-semver <name>] [\-r <remote>] [\-m <commit info>] [\-\-no\-empty\-commit] [\-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\.
.
.P
This command always creates a release commit, which could be empty if nothing changed\. It works like \fBgit merge \-\-no\-ff\fR\. If you don\'t like the behavior, you could add \fB\-\-no\-empty\-commit\fR to skip it\.
.
.P
Optionally it generates a changelog (see git\-changelog) and a remote can be defined\. The order of first \-c or \-r does not matter\.
.
.P
@ -43,6 +46,12 @@ The "remote" repository that is destination of a push operation: it is passed to
use the custom commit information instead of the default message "Release <tagname>" \.
.
.P
\-\-no\-empty\-commit
.
.P
Avoid creating empty commit if nothing could be committed\.
.
.P
\-c
.
.P

View file

@ -76,12 +76,14 @@
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<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>
<p><code>git-release</code> [&lt;tagname&gt; | --semver &lt;name&gt;] [-r &lt;remote&gt;] [-m &lt;commit info&gt;] [--no-empty-commit] [-c] [[--] &lt;hook arguments...&gt;]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p> Commits changes with message "Release &lt;tagname&gt;" or custom commit information, tags with the given &lt;tagname&gt; and pushes the branch / tags.</p>
<p> This command always creates a release commit, which could be empty if nothing changed. It works like <code>git merge --no-ff</code>. If you don't like the behavior, you could add <code>--no-empty-commit</code> to skip it.</p>
<p> Optionally it generates a changelog (see git-changelog) and a remote can be defined. The order of first -c or -r does not matter.</p>
<p> If <code>.git/hook/pre-release</code> or <code>.git/hook/post-release</code> exist, they will be triggered with <code>tagname</code> and extra hook arguments before/after the release.</p>
@ -106,6 +108,10 @@
<p> use the custom commit information instead of the default message "Release &lt;tagname&gt;" .</p>
<p> --no-empty-commit</p>
<p> Avoid creating empty commit if nothing could be committed.</p>
<p> -c</p>
<p> Generates or populates the changelog with all commit message since the last tag. For more info see git-changelog..</p>
@ -141,8 +147,8 @@ populate changelog, and push to specific remote.</p>
<h2 id="AUTHOR">AUTHOR</h2>
<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>
<p>Written by Tj Holowaychuk &lt;<a href="&#x6d;&#97;&#x69;&#108;&#x74;&#x6f;&#x3a;&#x74;&#106;&#x40;&#118;&#x69;&#115;&#105;&#x6f;&#110;&#45;&#x6d;&#x65;&#x64;&#105;&#x61;&#x2e;&#99;&#97;" data-bare-link="true">&#116;&#x6a;&#64;&#118;&#105;&#115;&#105;&#111;&#x6e;&#45;&#x6d;&#x65;&#x64;&#105;&#x61;&#46;&#99;&#x61;</a>&gt;
Extended by David Hartmann &lt;<a href="&#x6d;&#x61;&#105;&#x6c;&#x74;&#111;&#58;&#100;&#104;&#x40;&#116;&#115;&#108;&#46;&#x69;&#111;" data-bare-link="true">&#100;&#x68;&#64;&#116;&#x73;&#108;&#46;&#105;&#x6f;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -155,7 +161,7 @@ Extended by David Hartmann &lt;<a href="&#109;&#97;&#x69;&#108;&#116;&#111;&#x3a
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>December 2017</li>
<li class='tc'>February 2018</li>
<li class='tr'>git-release(1)</li>
</ol>

View file

@ -3,12 +3,14 @@ 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;] [-c] [[--] &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] [[--] &lt;hook arguments...&gt;]
## DESCRIPTION
Commits changes with message "Release &lt;tagname&gt;" or custom commit information, tags with the given &lt;tagname&gt; and pushes the branch / tags.
This command always creates a release commit, which could be empty if nothing changed. It works like `git merge --no-ff`. If you don't like the behavior, you could add `--no-empty-commit` to skip it.
Optionally it generates a changelog (see git-changelog) and a remote can be defined. The order of first -c or -r does not matter.
If `.git/hook/pre-release` or `.git/hook/post-release` exist, they will be triggered with `tagname` and extra hook arguments before/after the release.
@ -33,6 +35,10 @@ git-release(1) -- Commit, tag and push changes to the repository
use the custom commit information instead of the default message "Release &lt;tagname&gt;" .
--no-empty-commit
Avoid creating empty commit if nothing could be committed.
-c
Generates or populates the changelog with all commit message since the last tag. For more info see git-changelog..