add squash option to git-feature

This commit is contained in:
Carlos Prado 2020-04-04 00:28:29 +02:00
commit c038741194
4 changed files with 67 additions and 49 deletions

View file

@ -1,55 +1,59 @@
#!/usr/bin/env bash
branch_prefix=feature
merge_mode="--no-ff"
declare -a argv
while test $# != 0
do
case $1 in
-a|--alias )
if [[ -n $2 ]]
then
shift # shift -a|-alias
branch_prefix=$1
else
argv+=($1) # treat tail '-a' as <name>
fi
;;
-r|--remote )
if [[ -n $2 ]]
then
remote=$2
shift
else
remote="origin"
fi
;;
* )
argv+=($1)
;;
esac
shift
case $1 in
-a|--alias )
if [[ -n $2 ]]
then
shift # shift -a|-alias
branch_prefix=$1
else
argv+=($1) # treat tail '-a' as <name>
fi
;;
-r|--remote )
if [[ -n $2 ]]
then
remote=$2
shift
else
remote="origin"
fi
;;
--squash )
merge_mode="--squash"
;;
* )
argv+=($1)
;;
esac
shift
done
concatargs(){
str=$(IFS='-'; echo "$*")
branch="$branch_prefix"/$str
concatargs() {
str=$(IFS='-'; echo "$*")
branch="$branch_prefix"/$str
}
if test "${argv[0]}" = "finish"; then
test -z "${argv[1]}" && echo "$branch_prefix" "<name> required." 1>&2 && exit 1
branch="$branch_prefix"/"${argv[1]}"
git merge --no-ff "$branch" && git delete-branch "$branch"
test -z "${argv[1]}" && echo "$branch_prefix" "<name> required." 1>&2 && exit 1
branch="$branch_prefix"/"${argv[1]}"
git merge ${merge_mode} "$branch" && git delete-branch "$branch"
else
test -z "${argv[0]}" && echo "$branch_prefix" "<name> required." 1>&2 && exit 1
if test -n "${argv[1]}"; then
concatargs "${argv[@]}"
else
branch="$branch_prefix"/"${argv[0]}"
fi
if [[ -n $remote ]]
then
git create-branch -r $remote $branch
else
git create-branch $branch
fi
test -z "${argv[0]}" && echo "$branch_prefix" "<name> required." 1>&2 && exit 1
if test -n "${argv[1]}"; then
concatargs "${argv[@]}"
else
branch="$branch_prefix"/"${argv[0]}"
fi
if [[ -n $remote ]]
then
git create-branch -r $remote $branch
else
git create-branch $branch
fi
fi

View file

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-FEATURE" "1" "October 2017" "" "Git Extras"
.TH "GIT\-FEATURE" "1" "April 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-feature\fR \- Create/Merge feature branch
@ -25,6 +25,12 @@ use \fBbranch_prefix\fR instead of \fBfeature\fR
Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is not supplied, use \fBorigin\fR by default\.
.
.P
<\-\-squash>
.
.P
Run a squash merge\.
.
.P
<finish>
.
.P
@ -51,7 +57,7 @@ $ git alias features "feature \-a features"
$ git features dependencies
$ (features/dependencies) \.\.\.
$ (features/dependencies) git checkout master
$ git features finish dependencies
$ git features finish \-\-squash dependencies
$ git feature dependencies \-r upstream
.

View file

@ -92,6 +92,10 @@
<p> Setup a remote tracking branch using <code>remote_name</code>. If <code>remote_name</code> is not supplied, use <code>origin</code> by default.</p>
<p> &lt;--squash&gt;</p>
<p> Run a squash merge.</p>
<p> &lt;finish&gt;</p>
<p> Merge and delete the feature branch.</p>
@ -113,15 +117,15 @@ $ git alias features "feature -a features"
$ git features dependencies
$ (features/dependencies) ...
$ (features/dependencies) git checkout master
$ git features finish dependencies
$ git features finish --squash dependencies
$ git feature dependencies -r upstream
</code></pre>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Jesús Espino &lt;<a href="&#x6d;&#97;&#105;&#x6c;&#x74;&#x6f;&#58;&#106;&#101;&#115;&#112;&#105;&#x6e;&#111;&#103;&#x40;&#x67;&#x6d;&#x61;&#105;&#x6c;&#46;&#x63;&#111;&#109;" data-bare-link="true">&#106;&#101;&#x73;&#112;&#105;&#110;&#x6f;&#x67;&#64;&#x67;&#109;&#x61;&#x69;&#108;&#46;&#x63;&#111;&#109;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#x6d;&#97;&#105;&#108;&#116;&#x6f;&#58;&#109;&#97;&#114;&#x6b;&#x2e;&#112;&#x69;&#x74;&#109;&#97;&#x6e;&#64;&#x67;&#109;&#97;&#105;&#x6c;&#46;&#99;&#x6f;&#109;" data-bare-link="true">&#x6d;&#97;&#114;&#107;&#46;&#x70;&#x69;&#116;&#109;&#x61;&#110;&#x40;&#x67;&#109;&#97;&#x69;&#x6c;&#x2e;&#x63;&#x6f;&#109;</a>&gt;</p>
<p>Written by Jesús Espino &lt;<a href="&#109;&#97;&#x69;&#108;&#x74;&#x6f;&#x3a;&#106;&#x65;&#115;&#112;&#x69;&#x6e;&#111;&#103;&#x40;&#103;&#109;&#97;&#x69;&#108;&#46;&#99;&#x6f;&#109;" data-bare-link="true">&#106;&#x65;&#x73;&#x70;&#105;&#x6e;&#x6f;&#103;&#64;&#103;&#x6d;&#x61;&#x69;&#108;&#46;&#x63;&#111;&#x6d;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#x6d;&#x61;&#105;&#108;&#x74;&#111;&#58;&#x6d;&#97;&#114;&#x6b;&#x2e;&#x70;&#x69;&#x74;&#109;&#97;&#x6e;&#x40;&#103;&#x6d;&#x61;&#105;&#x6c;&#46;&#x63;&#x6f;&#109;" data-bare-link="true">&#x6d;&#x61;&#114;&#107;&#46;&#112;&#105;&#116;&#109;&#97;&#x6e;&#64;&#103;&#109;&#97;&#x69;&#x6c;&#x2e;&#99;&#x6f;&#109;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -134,7 +138,7 @@ Modified by Mark Pitman &lt;<a href="&#x6d;&#97;&#105;&#108;&#116;&#x6f;&#58;&#1
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>October 2017</li>
<li class='tc'>April 2020</li>
<li class='tr'>git-feature(1)</li>
</ol>

View file

@ -19,6 +19,10 @@ git-feature(1) -- Create/Merge feature branch
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
&lt;--squash&gt;
Run a squash merge.
&lt;finish&gt;
Merge and delete the feature branch.
@ -40,7 +44,7 @@ git-feature(1) -- Create/Merge feature branch
$ git features dependencies
$ (features/dependencies) ...
$ (features/dependencies) git checkout master
$ git features finish dependencies
$ git features finish --squash dependencies
$ git feature dependencies -r upstream