Merge pull request #940 from overengineer/feature/magic

git-magic: Automated commit messages
This commit is contained in:
罗泽轩 2021-10-10 12:09:51 +08:00 committed by GitHub
commit b33ec65e5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 449 additions and 0 deletions

View file

@ -36,6 +36,7 @@
- [`git local-commits`](#git-local-commits)
- [`git lock`](#git-lock)
- [`git locked`](#git-locked)
- [`git magic`](#git-magic)
- [`git merge-into`](#git-merge-into)
- [`git merge-repo`](#git-merge-repo)
- [`git missing`](#git-missing)
@ -1544,3 +1545,7 @@ total 308
## git abort
Abort current rebase, merge or cherry-pick, without the need to find exact command in history.
## git magic
Commits changes with a generated message.

87
bin/git-magic Executable file
View file

@ -0,0 +1,87 @@
#!/usr/bin/env bash
# Bash unofficial strict mode
set -eo pipefail
IFS=$'\n\t'
cd "$(git rev-parse --show-toplevel)"
USAGE='git-magic [-a] [-m msg] [-e] [-p] [-f]'
ALL=false
PUSH=false
FORCE=''
ARGS=()
while getopts "m:eapfh" arg; do
case "${arg}" in
m)
ARGS+=("-m")
ARGS+=("${OPTARG}")
;;
e)
ARGS+=("-e")
;;
a)
ALL=true
;;
p)
PUSH=true
;;
f)
FORCE='-f'
;;
h)
echo $USAGE
exit 0
;;
?)
echo "${USAGE}"
exit 1
;;
esac
done
shift $((OPTIND-1))
if [[ $# != 0 ]]; then
echo "Unknown arguments: $@"
echo "${USAGE}"
exit 1
fi
set -- "${ARGS[@]}" # restore positional parameters
if [[ $ALL == true ]]; then
# Check if there is no changes to stage
if [[ -z $(git status --porcelain) ]]; then
echo "No changes to commit"
exit 0
fi
# Get confirmation from user
git status
echo "Everything will be added"
read -p "Press enter to continue"
# Restore staging area so that, for example,
# add and modify will not be separate entries in status
git restore --staged . || true
git add .
fi
# Commit with generated message
git commit --no-edit "$@" -m "$(git status --porcelain -uno)"
if [[ $PUSH == true ]]; then
git push $FORCE
fi
# --no-edit by default. use option -e to override this
# Arguments are passed with quoted "$@" to avoid misparsing
# Generated message comes after user provided arguments
# so that user can insert title before it

View file

@ -379,6 +379,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
local-commits:'list local commits' \
lock:'lock a file excluded from version control' \
locked:'ls files that have been locked' \
magic:'commits everything with a generated message' \
merge-into:'merge one branch into another' \
merge-repo:'merge two repo histories' \
missing:'show commits missing from another branch' \

View file

@ -63,6 +63,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-local-commits(1)** List local commits
- **git-lock(1)** Lock a file excluded from version control
- **git-locked(1)** ls files that have been locked
- **git-magic(1)** Automate add/commit/push routines
- **git-merge-into(1)** Merge one branch into another
- **git-merge-repo(1)** Merge two repo histories
- **git-missing(1)** Show commits missing from another branch

102
man/git-magic.1 Normal file
View file

@ -0,0 +1,102 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-MAGIC" "1" "October 2021" "" "Git Extras"
.
.SH "NAME"
\fBgit\-magic\fR \- Automate add/commit/push routines
.
.SH "SYNOPSIS"
\fBgit\-magic\fR [\-a] [\-m \fImsg\fR] [\-e] [\-p] [\-f]
.
.SH "DESCRIPTION"
Produces summary of changes for commit message from \fBgit status \-\-porcelain\fR output\. Commits staged changes with the generated commit message and opens editor to modify generated commit message optionally\. Also staging and pushing can be automated optinally\.
.
.SH "OPTIONS"
\-a
.
.P
Adds everything including untracked files\.
.
.P
\-m \fImsg\fR
.
.P
Use the given \fImsg\fR as the commit message\. If multiple \-m options are given, their values are concatenated as separate paragraphs\. Passed to git commit command\. The generated is appended to user\-given messages\.
.
.P
\-e
.
.P
This option lets you further edit the generated message\. Passed to git commit command\.
.
.P
\-p
.
.P
Runs \fBgit push\fR after commit\.
.
.P
\-f
.
.P
Adds \fB\-f\fR option to \fBgit push\fR command\.
.
.P
\-h
.
.P
Prints synopsis\.
.
.SH "EXAMPLES"
This example stages all changes then commits with automatic commit message\.
.
.IP "" 4
.
.nf
$ git magic \-a
[feature/magic dc2a11e] A man/git\-magic\.md
1 file changed, 37 insertions(+)
create mode 100644 man/git\-auto\.md
# git log
Author: overengineer <54alpersaid@gmail\.com>
Date: Thu Sep 30 20:14:22 2021 +0300
M man/git\-magic\.md
.
.fi
.
.IP "" 0
.
.P
\fB\-m\fR option PREPENDS generated message\.
.
.IP "" 4
.
.nf
$ git magic \-am "Added documentation for git magic"
[feature/magic dc2a11e] Added documentation for git magic
1 file changed, 42 insertions(+), 0 deletions(\-)
create mode 100644 A man/git\-auto\.md
$ git log
Author: overengineer <54alpersaid@gmail\.com>
Date: Thu Sep 30 20:14:22 2021 +0300
Added documentation for git magic
M man/git\-magic\.md
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Alper S\. Soylu \fI54alpersaid@gmail\.com\fR
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>

167
man/git-magic.html Normal file
View file

@ -0,0 +1,167 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' value='text/html;charset=utf8'>
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
<title>git-magic(1) - Automate add/commit/push routines</title>
<style type='text/css' media='all'>
/* style: man */
body#manpage {margin:0}
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
.mp h2 {margin:10px 0 0 0}
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
.mp h3 {margin:0 0 0 4ex}
.mp dt {margin:0;clear:left}
.mp dt.flush {float:left;width:8ex}
.mp dd {margin:0 0 0 9ex}
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
.mp pre {margin-bottom:20px}
.mp pre+h2,.mp pre+h3 {margin-top:22px}
.mp h2+pre,.mp h3+pre {margin-top:5px}
.mp img {display:block;margin:auto}
.mp h1.man-title {display:none}
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
.mp h2 {font-size:16px;line-height:1.25}
.mp h1 {font-size:20px;line-height:2}
.mp {text-align:justify;background:#fff}
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
.mp u {text-decoration:underline}
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
.mp b.man-ref {font-weight:normal;color:#434241}
.mp pre {padding:0 4ex}
.mp pre code {font-weight:normal;color:#434241}
.mp h2+pre,h3+pre {padding-left:0}
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
ol.man-decor {width:100%}
ol.man-decor li.tl {text-align:left}
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
ol.man-decor li.tr {text-align:right;float:right}
</style>
</head>
<!--
The following styles are deprecated and will be removed at some point:
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
.man-navigation should be used instead.
-->
<body id='manpage'>
<div class='mp' id='man'>
<div class='man-navigation' style='display:none'>
<a href="#NAME">NAME</a>
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#DESCRIPTION">DESCRIPTION</a>
<a href="#OPTIONS">OPTIONS</a>
<a href="#EXAMPLES">EXAMPLES</a>
<a href="#AUTHOR">AUTHOR</a>
<a href="#REPORTING-BUGS">REPORTING BUGS</a>
<a href="#SEE-ALSO">SEE ALSO</a>
</div>
<ol class='man-decor man-head man head'>
<li class='tl'>git-magic(1)</li>
<li class='tc'>Git Extras</li>
<li class='tr'>git-magic(1)</li>
</ol>
<h2 id="NAME">NAME</h2>
<p class="man-name">
<code>git-magic</code> - <span class="man-whatis">Automate add/commit/push routines</span>
</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-magic</code> [-a] [-m <var>msg</var>] [-e] [-p] [-f]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p>Produces summary of changes for commit message from <code>git status --porcelain</code> output.
Commits staged changes with the generated commit message and
opens editor to modify generated commit message optionally.
Also staging and pushing can be automated optinally.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p>-a</p>
<p>Adds everything including untracked files.</p>
<p>-m <var>msg</var></p>
<p>Use the given <var>msg</var> as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.
Passed to git commit command. The generated is appended to user-given messages.</p>
<p>-e</p>
<p>This option lets you further edit the generated message.
Passed to git commit command.</p>
<p>-p</p>
<p>Runs <code>git push</code> after commit.</p>
<p>-f</p>
<p>Adds <code>-f</code> option to <code>git push</code> command.</p>
<p>-h</p>
<p>Prints synopsis.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p>This example stages all changes then commits with automatic commit message.</p>
<pre><code>$ git magic -a
[feature/magic dc2a11e] A man/git-magic.md
1 file changed, 37 insertions(+)
create mode 100644 man/git-auto.md
# git log
Author: overengineer &lt;54alpersaid@gmail.com&gt;
Date: Thu Sep 30 20:14:22 2021 +0300
M man/git-magic.md
</code></pre>
<p><code>-m</code> option PREPENDS generated message.</p>
<pre><code>$ git magic -am "Added documentation for git magic"
[feature/magic dc2a11e] Added documentation for git magic
1 file changed, 42 insertions(+), 0 deletions(-)
create mode 100644 A man/git-auto.md
$ git log
Author: overengineer &lt;54alpersaid@gmail.com&gt;
Date: Thu Sep 30 20:14:22 2021 +0300
Added documentation for git magic
M man/git-magic.md
</code></pre>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Alper S. Soylu <a href="&#x6d;&#x61;&#105;&#x6c;&#x74;&#x6f;&#58;&#x35;&#x34;&#97;&#x6c;&#112;&#x65;&#114;&#115;&#x61;&#105;&#x64;&#x40;&#103;&#x6d;&#x61;&#x69;&#108;&#46;&#x63;&#x6f;&#x6d;" data-bare-link="true">&#x35;&#52;&#x61;&#108;&#x70;&#x65;&#x72;&#x73;&#97;&#105;&#100;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#x63;&#111;&#x6d;</a></p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
<p>&lt;<a href="https://github.com/tj/git-extras/issues" data-bare-link="true">https://github.com/tj/git-extras/issues</a>&gt;</p>
<h2 id="SEE-ALSO">SEE ALSO</h2>
<p>&lt;<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>&gt;</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>October 2021</li>
<li class='tr'>git-magic(1)</li>
</ol>
</div>
</body>
</html>

85
man/git-magic.md Normal file
View file

@ -0,0 +1,85 @@
git-magic(1) -- Automate add/commit/push routines
================================
## SYNOPSIS
`git-magic` [-a] [-m <msg>] [-e] [-p] [-f]
## DESCRIPTION
Produces summary of changes for commit message from `git status --porcelain` output.
Commits staged changes with the generated commit message and
opens editor to modify generated commit message optionally.
Also staging and pushing can be automated optinally.
## OPTIONS
-a
Adds everything including untracked files.
-m <msg>
Use the given <msg> as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.
Passed to git commit command. The generated is appended to user-given messages.
-e
This option lets you further edit the generated message.
Passed to git commit command.
-p
Runs `git push` after commit.
-f
Adds `-f` option to `git push` command.
-h
Prints synopsis.
## EXAMPLES
This example stages all changes then commits with automatic commit message.
```
$ git magic -a
[feature/magic dc2a11e] A man/git-magic.md
1 file changed, 37 insertions(+)
create mode 100644 man/git-auto.md
# git log
Author: overengineer <54alpersaid@gmail.com>
Date: Thu Sep 30 20:14:22 2021 +0300
M man/git-magic.md
```
`-m` option PREPENDS generated message.
```
$ git magic -am "Added documentation for git magic"
[feature/magic dc2a11e] Added documentation for git magic
1 file changed, 42 insertions(+), 0 deletions(-)
create mode 100644 A man/git-auto.md
$ git log
Author: overengineer <54alpersaid@gmail.com>
Date: Thu Sep 30 20:14:22 2021 +0300
Added documentation for git magic
M man/git-magic.md
```
## AUTHOR
Written by Alper S. Soylu <54alpersaid@gmail.com>
## REPORTING BUGS
&lt;<https://github.com/tj/git-extras/issues>&gt;
## SEE ALSO
&lt;<https://github.com/tj/git-extras>&gt;

View file

@ -36,6 +36,7 @@ git-info(1) git-info
git-local-commits(1) git-local-commits
git-lock(1) git-lock
git-locked(1) git-locked
git-magic(1) git-magic
git-merge-into(1) git-merge-into
git-merge-repo(1) git-merge-repo
git-missing(1) git-missing