implements remote pref for create-branch

This commit is contained in:
Brian Murrell 2019-06-21 06:20:16 -07:00
parent 820b7cd41b
commit 7d3ab83ec3
6 changed files with 152 additions and 32 deletions

View file

@ -1,10 +1,10 @@
#!/usr/bin/env bash
test $# -eq 0 && echo "branch argument required." 1>&2 && exit 1
# preference takes lowest priority; look for remote from prefs first
REMOTE_PREF=`git config git-extras.create-branch.remote`
if [ ${REMOTE_PREF} == "true" ]; then
REMOTE=origin
elif [ "$REMOTE_PREF" != ""]; then
if [ -n "$REMOTE_PREF" ]; then
REMOTE=$REMOTE_PREF
fi
@ -26,17 +26,22 @@ do
shift
done
# handle ambiguous `-r` option argument by shift
if [[ -z $BRANCH ]] && [[ -n $REMOTE ]]
then
BRANCH=$REMOTE
REMOTE=origin
fi
test -z $BRANCH && echo "branch required." 1>&2 && exit 1
test -z $BRANCH && echo "branch argument required." 1>&2 && exit 1
if [[ -n $REMOTE ]]
then
git ls-remote --exit-code $REMOTE 1>/dev/null 2>/tmp/ls-remote-error
if [ $? = 0 ]
REMOTE_EXIT=$?
REMOTE_ERROR=$(</tmp/ls-remote-error)
rm -f /tmp/ls-remote-error
if [ $REMOTE_EXIT -eq 0 ]
then
git push $REMOTE HEAD:refs/heads/$BRANCH
git fetch $REMOTE
@ -44,8 +49,9 @@ then
exit $?
else
echo
echo " Error connecting to remote '$REMOTE': `cat /tmp/ls-remote-error`"
rm -f /tmp/ls-remote-error
echo " Error connecting to remote '$REMOTE': $REMOTE_ERROR"
echo
exit $REMOTE_EXIT
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\-CREATE\-BRANCH" "1" "October 2017" "" "Git Extras"
.TH "GIT\-CREATE\-BRANCH" "1" "June 2019" "" "Git Extras"
.
.SH "NAME"
\fBgit\-create\-branch\fR \- Create branches
@ -24,26 +24,76 @@ Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is
.P
The name of the branch to create\.
.
.SH "EXAMPLES"
.SH "PREFERENCES"
You may save your default preference for the \fBremote\fR option above by using \fBgit config\fR with the key \fBgit\-extras\.create\-branch\.remote\fR whose value will be the default remote when \fB[\-r|\-\-remote]\fR is not specified\.
.
.IP "" 4
.
.nf
$ git config git\-extras\.create\-branch\.remote lucinda
.
.fi
.
.IP "" 0
.
.P
The command line option \fB\-r|\-\-remote\fR will override this preference\.
.
.SH "EXAMPLES"
With no remote preference set:
.
.IP "" 4
.
.nf
# creates local branch \'integration\'
$ git create\-branch integration
# creates local & remote branch \'integration\' (on default \'origin\')
$ git create\-branch \-r integration
# creates local & remote branch \'integration\' on \'upstream\'
$ git create\-branch \-r upstream integration
.
.fi
.
.IP "" 0
.
.P
With \fBgit\-extras\.create\-branch\.remote\fR preference set to \'lucinda\':
.
.IP "" 4
.
.nf
# creates local & remote branch \'integration\' (on preference \'lucinda\')
$ git create\-branch integration
# overriding preference, using default `\-r` of \'origin\'
# creates local & remote branch \'integration\' on default \'origin\'
$ git create\-branch \-r integration
# overriding preference, using specified `\-r` of \'upstream\'
# creates local & remote branch \'integration\' on \'upstream\'
$ git create\-branch \-r upstream integration
.
.fi
.
.IP "" 0
.
.SH "NOTES"
As of 4\.4\.0, the default behavior has changed\. \fBgit\-create\-branch\fR will no longer automatically setup a remote tracking branch unless the \fB\-r|\-remote\fR option is specified\.
.
.IP "\(bu" 4
As of 4\.4\.0, the default behavior has changed\. \fBgit\-create\-branch\fR will no longer automatically setup a remote tracking branch unless the \fB\-r|\-remote\fR option is specified\. See additional note on preference feature in 4\.8\.0\-dev below\.
.
.IP "\(bu" 4
As of 4\.8\.0\-dev, the \fBremote\fR option can be set via \fBgit config\fR preference as described in \fIPreferences\fR section\.
.
.IP "" 0
.
.SH "AUTHOR"
Written by Jonhnny Weslley <\fIjw@jonhnnyweslley\.net\fR>
.
.br
Modified by Mark Pitman <\fImark\.pitman@gmail\.com\fR>
Written by Jonhnny Weslley <\fIjw@jonhnnyweslley\.net\fR> Modified by Mark Pitman <\fImark\.pitman@gmail\.com\fR>, Brian Murrell <\fIbtmurrell@gmail\.com\fR>\.
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>

View file

@ -57,6 +57,7 @@
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#DESCRIPTION">DESCRIPTION</a>
<a href="#OPTIONS">OPTIONS</a>
<a href="#PREFERENCES">PREFERENCES</a>
<a href="#EXAMPLES">EXAMPLES</a>
<a href="#NOTES">NOTES</a>
<a href="#AUTHOR">AUTHOR</a>
@ -81,35 +82,67 @@
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p> Creates local branch named &lt;branchname&gt; and optionally sets up a remote tracking branch.</p>
<p>Creates local branch named &lt;branchname&gt; and optionally sets up a remote tracking branch.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p> &lt;-r|--remote [remote_name]&gt;</p>
<p>&lt;-r|--remote [remote_name]&gt;</p>
<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>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;branchname&gt;</p>
<p>&lt;branchname&gt;</p>
<p> The name of the branch to create.</p>
<p>The name of the branch to create.</p>
<h2 id="PREFERENCES">PREFERENCES</h2>
<p>You may save your default preference for the <code>remote</code> option above by using <code>git config</code> with the key <code>git-extras.create-branch.remote</code> whose value will be the default remote when <code>[-r|--remote]</code> is not specified.</p>
<pre><code>$ git config git-extras.create-branch.remote lucinda
</code></pre>
<p>The command line option <code>-r|--remote</code> will override this preference.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<pre><code>$ git create-branch integration
<p>With no remote preference set:</p>
<pre><code># creates local branch 'integration'
$ git create-branch integration
# creates local &amp; remote branch 'integration' (on default 'origin')
$ git create-branch -r integration
# creates local &amp; remote branch 'integration' on 'upstream'
$ git create-branch -r upstream integration
</code></pre>
<p>With <code>git-extras.create-branch.remote</code> preference set to 'lucinda':</p>
<pre><code># creates local &amp; remote branch 'integration' (on preference 'lucinda')
$ git create-branch integration
# overriding preference, using default `-r` of 'origin'
# creates local &amp; remote branch 'integration' on default 'origin'
$ git create-branch -r integration
# overriding preference, using specified `-r` of 'upstream'
# creates local &amp; remote branch 'integration' on 'upstream'
$ git create-branch -r upstream integration
</code></pre>
<h2 id="NOTES">NOTES</h2>
<p>As of 4.4.0, the default behavior has changed. <code>git-create-branch</code> will no longer automatically setup a remote tracking branch unless the <code>-r|-remote</code> option is specified.</p>
<ul>
<li><p>As of 4.4.0, the default behavior has changed. <code>git-create-branch</code> will no longer automatically setup a remote tracking branch unless the <code>-r|-remote</code> option is specified. See additional note on preference feature in 4.8.0-dev below.</p></li>
<li><p>As of 4.8.0-dev, the <code>remote</code> option can be set via <code>git config</code> preference as described in <a href="#PREFERENCES" data-bare-link="true">Preferences</a> section.</p></li>
</ul>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Jonhnny Weslley &lt;<a href="&#109;&#97;&#x69;&#108;&#x74;&#111;&#x3a;&#x6a;&#x77;&#x40;&#106;&#x6f;&#110;&#x68;&#110;&#x6e;&#x79;&#x77;&#101;&#115;&#108;&#108;&#101;&#121;&#46;&#x6e;&#101;&#x74;" data-bare-link="true">&#106;&#119;&#64;&#106;&#111;&#x6e;&#104;&#110;&#x6e;&#x79;&#x77;&#101;&#115;&#x6c;&#x6c;&#x65;&#121;&#x2e;&#110;&#101;&#116;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#109;&#97;&#x69;&#108;&#116;&#x6f;&#x3a;&#109;&#97;&#114;&#107;&#46;&#112;&#105;&#x74;&#x6d;&#97;&#x6e;&#64;&#x67;&#109;&#97;&#105;&#108;&#x2e;&#x63;&#111;&#x6d;" data-bare-link="true">&#x6d;&#97;&#x72;&#x6b;&#46;&#112;&#x69;&#x74;&#109;&#97;&#x6e;&#64;&#103;&#x6d;&#97;&#105;&#x6c;&#x2e;&#x63;&#x6f;&#109;</a>&gt;</p>
<p>Written by Jonhnny Weslley &lt;<a href="&#109;&#97;&#105;&#108;&#x74;&#x6f;&#58;&#x6a;&#119;&#64;&#x6a;&#x6f;&#x6e;&#x68;&#110;&#x6e;&#x79;&#119;&#x65;&#x73;&#x6c;&#x6c;&#101;&#121;&#46;&#x6e;&#101;&#116;" data-bare-link="true">&#106;&#x77;&#x40;&#106;&#111;&#x6e;&#104;&#x6e;&#x6e;&#x79;&#x77;&#x65;&#x73;&#108;&#108;&#101;&#x79;&#x2e;&#110;&#101;&#x74;</a>&gt;
Modified by Mark Pitman &lt;<a href="&#x6d;&#97;&#105;&#108;&#116;&#111;&#58;&#x6d;&#97;&#114;&#x6b;&#46;&#x70;&#x69;&#116;&#x6d;&#97;&#x6e;&#64;&#x67;&#109;&#x61;&#105;&#108;&#46;&#99;&#x6f;&#x6d;" data-bare-link="true">&#109;&#97;&#114;&#x6b;&#46;&#112;&#x69;&#116;&#x6d;&#x61;&#x6e;&#x40;&#103;&#x6d;&#x61;&#x69;&#108;&#x2e;&#99;&#111;&#x6d;</a>&gt;, Brian Murrell &lt;<a href="&#109;&#x61;&#x69;&#108;&#x74;&#111;&#58;&#98;&#x74;&#x6d;&#117;&#x72;&#x72;&#101;&#x6c;&#x6c;&#x40;&#x67;&#109;&#x61;&#x69;&#108;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#98;&#x74;&#x6d;&#x75;&#114;&#x72;&#101;&#x6c;&#x6c;&#64;&#x67;&#x6d;&#97;&#x69;&#108;&#46;&#99;&#x6f;&#109;</a>&gt;.</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -122,7 +155,7 @@ Modified by Mark Pitman &lt;<a href="&#109;&#97;&#x69;&#108;&#116;&#x6f;&#x3a;&#
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>October 2017</li>
<li class='tc'>June 2019</li>
<li class='tr'>git-create-branch(1)</li>
</ol>

View file

@ -7,33 +7,62 @@ git-create-branch(1) -- Create branches
## DESCRIPTION
Creates local branch named &lt;branchname&gt; and optionally sets up a remote tracking branch.
Creates local branch named &lt;branchname&gt; and optionally sets up a remote tracking branch.
## OPTIONS
&lt;-r|--remote [remote_name]&gt;
&lt;-r|--remote [remote_name]&gt;
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
&lt;branchname&gt;
&lt;branchname&gt;
The name of the branch to create.
The name of the branch to create.
## PREFERENCES
You may save your default preference for the `remote` option above by using `git config` with the key `git-extras.create-branch.remote` whose value will be the default remote when `[-r|--remote]` is not specified.
$ git config git-extras.create-branch.remote lucinda
The command line option `-r|--remote` will override this preference.
## EXAMPLES
With no remote preference set:
# creates local branch 'integration'
$ git create-branch integration
# creates local & remote branch 'integration' (on default 'origin')
$ git create-branch -r integration
# creates local & remote branch 'integration' on 'upstream'
$ git create-branch -r upstream integration
With `git-extras.create-branch.remote` preference set to 'lucinda':
# creates local & remote branch 'integration' (on preference 'lucinda')
$ git create-branch integration
# overriding preference, using default `-r` of 'origin'
# creates local & remote branch 'integration' on default 'origin'
$ git create-branch -r integration
# overriding preference, using specified `-r` of 'upstream'
# creates local & remote branch 'integration' on 'upstream'
$ git create-branch -r upstream integration
## NOTES
As of 4.4.0, the default behavior has changed. `git-create-branch` will no longer automatically setup a remote tracking branch unless the `-r|-remote` option is specified.
* As of 4.4.0, the default behavior has changed. `git-create-branch` will no longer automatically setup a remote tracking branch unless the `-r|-remote` option is specified. See additional note on preference feature in 4.8.0-dev below.
* As of 4.8.0-dev, the `remote` option can be set via `git config` preference as described in [Preferences](#PREFERENCES) section.
## AUTHOR
Written by Jonhnny Weslley &lt;<jw@jonhnnyweslley.net>&gt;
Modified by Mark Pitman &lt;<mark.pitman@gmail.com>&gt;
Written by Jonhnny Weslley &lt;<jw@jonhnnyweslley.net>&gt;
Modified by Mark Pitman &lt;<mark.pitman@gmail.com>&gt;, Brian Murrell &lt;<btmurrell@gmail.com>&gt;.
## REPORTING BUGS

View file

@ -68,6 +68,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-refactor(1)** Create refactor branch
- **git-release(1)** Commit, tag and push changes to the repository
- **git-rename-branch(1)** rename local branch and push to remote
- **git-rename-remote(1)** Rename a remote
- **git-rename-tag(1)** Rename a tag
- **git-repl(1)** git read-eval-print-loop
- **git-reset-file(1)** Reset one file

View file

@ -47,6 +47,7 @@ git-rebase-patch(1) git-rebase-patch
git-refactor(1) git-refactor
git-release(1) git-release
git-rename-branch(1) git-rename-branch
git-rename-remote(1) git-rename-remote
git-rename-tag(1) git-rename-tag
git-repl(1) git-repl
git-reset-file(1) git-reset-file