feat: add reverse option to git-brv (#1123)

* feat: add reverse option to git-brv

When there are a large amount of branches it is often useful to see the
most recent branches last as they end up closer to the prompt. This adds
a new --reverse / -r option and an environment variable to set the
default behavior (GIT_BRV_REVERSE).

* git-brv: change to git option instead of environment variable and fix typo

* wrap git option in backticks for git-brv and fix git-feature title

* update git-feature docs

* fix missing breaks in git-feature.md
This commit is contained in:
Josh McKinney 2023-12-15 20:05:52 -08:00 committed by GitHub
parent cdbcef3227
commit 9049967232
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 141 additions and 47 deletions

View file

@ -359,6 +359,13 @@ $ git brv
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
```
When your repo has many branches, it can be more convenient to see this list in reverse. This can be set as the default by setting the git-extras.brv.reverse git option to true.
```bash
$ git brv --reverse
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv
```
## git repl

View file

@ -7,6 +7,20 @@ if ! (( BASH_VERSINFO[0] > 4 ||
exit 1
fi
# allow the user to set a default reverse option in an environment variable
reverse=$(git config --get git-extras.brv.reverse || echo false)
while [[ $# -gt 0 ]]; do
case $1 in
-r | --reverse)
reverse=true
shift
;;
*)
break
;;
esac
done
if [[ -t 1 ]]; then
shopt -s checkwinsize
COLUMNS=$(tput cols)
@ -36,9 +50,14 @@ for b in "${!upstream[@]}"; do
done
mapfile -t ordered < <(
# the reverse option of git-brv causes the sort to be sorted normally rather than in reverse
reverse_opt=""
if [[ $reverse = false ]]; then
reverse_opt="-r"
fi
for b in "${!date[@]}"; do
printf '%d\t%s\n' "${date[$b]}" "$b"
done | sort -rn | cut -f2-
done | sort -n $reverse_opt | cut -f2-
)
current=$(git symbolic-ref -q --short HEAD)

View file

@ -26,6 +26,10 @@ _git_authors(){
__gitcomp "-l --list --no-email"
}
_git_brv(){
__gitcomp "-r --reverse"
}
_git_coauthor(){
local oldIfs=$IFS
IFS=$'\n'

View file

@ -117,6 +117,11 @@ _git-authors() {
'--no-email[without email]' \
}
_git-brv() {
_arguments \
'(-r --reverse)'{-r,--reverse}'[reverse order]'
}
_git-changelog() {
_arguments \
'(-l --list)'{-l,--list}'[list commits]' \

View file

@ -82,6 +82,8 @@ complete -c git -n __fish_git_needs_command -a "$__fish_git_extras_commands"
# authors
complete -c git -f -n '__fish_git_using_command authors' -s l -l list -d 'show authors'
complete -c git -f -n '__fish_git_using_command authors' -l no-email -d 'without email'
# brv
complete -c git -f -n '__fish_git_using_command brv' -s r -l reverse -d 'reverse the sort order'
# bulk
complete -c git -n '__fish_git_using_command bulk' -s a -d 'Run a git command on all workspaces and their repositories'
complete -c git -n '__fish_git_using_command bulk' -s g -d 'Ask the user for confirmation on every execution'

View file

@ -1,17 +1,23 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-BRV" "1" "January 2020" "" "Git Extras"
.TH "GIT\-BRV" "1" "December 2023" "" "Git Extras"
.
.SH "NAME"
\fBgit\-brv\fR \- List branches sorted by their last commit date
.
.SH "SYNOPSIS"
\fBgit\-brv\fR
\fBgit\-brv\fR [\-r|\-\-reverse]
.
.SH "DESCRIPTION"
Pretty listing of branches sorted by the date of their last commit\.
.
.SH "OPTIONS"
\-r | \-\-reverse
.
.P
Reverses the output to put the most recent branch at the bottom of the list\. This is useful when there are large amount of branches as the most recent branch is shown just above the next prompt\. This can be configured as the default by setting \fBgit\-extras\.brv\.reverse\fR to true in your git options\.
.
.SH "EXAMPLES"
Simply run \fBgit brv\fR
.
@ -27,6 +33,21 @@ $ git brv
.
.IP "" 0
.
.P
To display the rows in reverse order: \fBgit brv \-\-reverse\fR
.
.IP "" 4
.
.nf
$ git brv \-\-reverse
2020\-01\-08 master origin/master 265b03e Merge pull request #816 from spacewander/git\-sed\-pathspec
2020\-01\-14 adds\-git\-brv fork/adds\-git\-brv 1ca0d76 Fixes #700: Adds git\-brv
.
.fi
.
.IP "" 0
.
.SH "AUTHOR"
Written by Øsse <\fIhttps://github\.com/Osse\fR>
.

View file

@ -56,6 +56,7 @@
<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>
@ -75,12 +76,18 @@
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-brv</code></p>
<p><code>git-brv</code> [-r|--reverse]</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p> Pretty listing of branches sorted by the date of their last commit.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p> -r | --reverse</p>
<p> Reverses the output to put the most recent branch at the bottom of the list. This is useful when there are large amount of branches as the most recent branch is shown just above the next prompt. This can be configured as the default by setting <code>git-extras.brv.reverse</code> to true in your git options.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p> Simply run <code>git brv</code></p>
@ -90,6 +97,13 @@
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
</code></pre>
<p> To display the rows in reverse order: <code>git brv --reverse</code></p>
<pre><code>$ git brv --reverse
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv
</code></pre>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Øsse &lt;<a href="https://github.com/Osse" data-bare-link="true">https://github.com/Osse</a>&gt;</p>
@ -105,7 +119,7 @@
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>January 2020</li>
<li class='tc'>December 2023</li>
<li class='tr'>git-brv(1)</li>
</ol>

View file

@ -3,12 +3,18 @@ git-brv(1) -- List branches sorted by their last commit date
## SYNOPSIS
`git-brv`
`git-brv` [-r|--reverse]
## DESCRIPTION
Pretty listing of branches sorted by the date of their last commit.
## OPTIONS
-r | --reverse
Reverses the output to put the most recent branch at the bottom of the list. This is useful when there are large amount of branches as the most recent branch is shown just above the next prompt. This can be configured as the default by setting `git-extras.brv.reverse` to true in your git options.
## EXAMPLES
Simply run `git brv`
@ -17,6 +23,11 @@ git-brv(1) -- List branches sorted by their last commit date
2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
To display the rows in reverse order: `git brv --reverse`
$ git brv --reverse
2020-01-08 master origin/master 265b03e Merge pull request #816 from spacewander/git-sed-pathspec
2020-01-14 adds-git-brv fork/adds-git-brv 1ca0d76 Fixes #700: Adds git-brv
## AUTHOR

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" "September 2023" "" "Git Extras"
.TH "GIT\-FEATURE" "1" "December 2023" "" "Git Extras"
.
.SH "NAME"
\fBgit\-feature\fR \- Create/Merge feature branch
@ -173,7 +173,7 @@ $ (features\.dependency\-tracking) git checkout master
$ git feature finish dependency tracking
.
.TP
Use a \fBgit\-feature\fR option flag as part of a branch name:
Use a \fBgit\-feature\fR option or the \fBfinish\fR command as part of a branch name:
.
.IP
$ git feature \-\- finish remote
@ -184,6 +184,12 @@ $ git feature \-\- finish remote
.br
$ (feature/finish\-remote) git commit \-m "Some changes"
.
.br
$ (feature/finish\-remote) git checkout main
.
.br
$ git feature finish \-\- finish remote
.
.SH "AUTHOR"
Written by Jesús Espino <\fIjespinog@gmail\.com\fR>
.

View file

@ -77,56 +77,58 @@
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-feature</code> [-a|--alias branch_prefix] [-s|--separator branch_separator] [-r|--remote [remote_name]] &lt;name&gt;<br />
<code>git-feature</code> [-a|--alias branch_prefix] [-s|--separator branch_separator] finish [--squash] &lt;name&gt;</p>
<p><code>git-feature</code> [-a|--alias <var>PREFIX</var>] [-s|--separator <var>SEPARATOR</var>] [-r|--remote [REMOTE_NAME]] [--from START_POINT] <var>NAME</var>...</p>
<p><code>git-feature</code> [-a|--alias <var>PREFIX</var>] [-s|--separator <var>SEPARATOR</var>] finish [--squash] <var>NAME</var>...</p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p>Create/Merge the given feature branch.</p>
<p>Create or merge the given feature branch. The feature branch name is made from the <var>PREFIX</var>, the <var>SEPARATOR</var>, and the <var>NAME</var> joined together.</p>
<p>The branch <code>name</code> may be specified as multiple words which will be joined with <code>-</code> characters. If any word should start with a <code>-</code>, the name should be preceded by <code>--</code>, which will signal that option parsing should be ignored.</p>
<p>The default <var>PREFIX</var> is <code>feature</code> and <var>SEPARATOR</var> is <code>/</code>, which can be changed (see OPTIONS and GIT CONFIG for details).</p>
<p>The branch <var>NAME</var> may be specified as multiple words which will be joined with <code>-</code>. If the branch name contains the word <code>finish</code> or is another OPTION, <code>--</code> should be passed to stop OPTION parsing. See the EXAMPLES for details.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p>&lt;-a|--alias branch_prefix&gt;</p>
<dl>
<dt><code>-a</code> <var>PREFIX</var>, <code>--alias</code> <var>PREFIX</var>:</dt><dd><p></p>
<p>The branch prefix to use, or <code>feature</code> if not supplied.</p>
<p>The branch prefix to use, or <code>feature</code> if not supplied.</p></dd>
<dt><code>-s</code> <var>SEPARATOR</var>, <code>--separator</code> <var>SEPARATOR</var>:</dt><dd><p></p>
<p>&lt;-s|--separator branch_separator&gt;</p>
<p>The separator to use for joining the branch prefix and the branch name, or <code>/</code> if not supplied.</p></dd>
<dt><code>-r</code> [REMOTE_NAME], <code>--remote</code> [REMOTE_NAME]:</dt><dd><p></p>
<p>The separator to use for joining the branch prefix and the branch name, or <code>/</code> if not supplied.</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></dd>
<dt><code>--from</code> START_POINT:</dt><dd><p></p>
<p>&lt;-r|--remote [remote_name]&gt;</p>
<p>Setup a start point when the branch created. If <code>--from</code> is not supplied, use the current branch by default. This option will be ignored when <code>finish</code>ing a branch.</p></dd>
<dt class="flush"><code>finish</code>:</dt><dd><p></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>Merge and delete the feature branch.</p></dd>
<dt><code>--squash</code>:</dt><dd><p></p>
<p>&lt;--from [start_point]&gt;</p>
<p>Run a squash merge when <code>finish</code>ing the feature branch.</p></dd>
<dt class="flush"><var>NAME</var>:</dt><dd><p></p>
<p>Setup a start point when the branch created. If <code>--from</code> is not supplied, use the current branch by default.</p>
<p>The name of the feature branch.</p></dd>
</dl>
<p>&lt;finish&gt;</p>
<p>Merge and delete the feature branch.</p>
<p>&lt;--squash&gt;</p>
<p>Run a squash merge.</p>
<p>&lt;name&gt;</p>
<p>The name of the feature branch.</p>
<h2 id="GIT-CONFIG">GIT CONFIG</h2>
<p>You can configure the default branch prefix and separator via git config options.</p>
<p> $ git config --global add git-extras.feature.prefix "branch_prefix"</p>
<dl>
<dt><code>git-extras.feature.prefix</code>:</dt><dd><p></p>
<p>The default <code>branch_prefix</code> is <code>feature</code>.</p>
<p> $ git config --global add git-extras.feature.prefix "prefix"</p></dd>
<dt><code>git-extras.feature.separator</code>:</dt><dd><p></p>
<p> $ git config --global add git-extras.feature.separator "-"</p>
<p> $ git config --global add git-extras.feature.separator "-"</p></dd>
</dl>
<p>The default <code>branch_separator</code> is <code>/</code>.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
@ -168,20 +170,22 @@ $ git feature dependency tracking<br />
$ (features.dependency-tracking) ...<br />
$ (features.dependency-tracking) git checkout master<br />
$ git feature finish dependency tracking</p></dd>
<dt>Use a <code>git-feature</code> option flag as part of a branch name:</dt><dd><p></p>
<dt>Use a <code>git-feature</code> option or the <code>finish</code> command as part of a branch name:</dt><dd><p></p>
<p>$ git feature -- --remote<br />
<p>$ git feature -- finish remote<br />
...<br />
$ (feature/--remote) git commit -m "Some changes"</p></dd>
$ (feature/finish-remote) git commit -m "Some changes"<br />
$ (feature/finish-remote) git checkout main<br />
$ git feature finish -- finish remote</p></dd>
</dl>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Jesús Espino &lt;<a href="&#109;&#97;&#x69;&#x6c;&#x74;&#111;&#x3a;&#106;&#x65;&#115;&#x70;&#x69;&#110;&#x6f;&#x67;&#64;&#103;&#x6d;&#97;&#105;&#108;&#x2e;&#99;&#111;&#109;" data-bare-link="true">&#106;&#x65;&#115;&#112;&#x69;&#x6e;&#x6f;&#x67;&#x40;&#103;&#109;&#x61;&#x69;&#108;&#46;&#x63;&#x6f;&#x6d;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#109;&#97;&#x69;&#108;&#x74;&#111;&#x3a;&#x6d;&#97;&#114;&#x6b;&#46;&#x70;&#105;&#x74;&#x6d;&#97;&#110;&#64;&#x67;&#x6d;&#x61;&#105;&#108;&#46;&#x63;&#111;&#x6d;" data-bare-link="true">&#x6d;&#97;&#114;&#x6b;&#46;&#x70;&#x69;&#x74;&#x6d;&#97;&#x6e;&#x40;&#x67;&#109;&#x61;&#105;&#108;&#46;&#x63;&#x6f;&#109;</a>&gt;<br />
Modified by Carlos Prado &lt;<a href="&#x6d;&#97;&#105;&#x6c;&#116;&#111;&#x3a;&#99;&#97;&#114;&#x6c;&#111;&#x73;&#46;&#x70;&#114;&#x61;&#100;&#111;&#64;&#x63;&#x70;&#x72;&#97;&#x64;&#x6f;&#103;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#x63;&#97;&#114;&#108;&#111;&#115;&#46;&#112;&#114;&#97;&#x64;&#x6f;&#x40;&#x63;&#112;&#114;&#x61;&#100;&#111;&#x67;&#46;&#x63;&#111;&#109;</a>&gt;<br />
Modified by Austin Ziegler &lt;<a href="&#109;&#x61;&#105;&#108;&#x74;&#111;&#58;&#104;&#97;&#108;&#x6f;&#115;&#116;&#x61;&#x74;&#117;&#x65;&#64;&#x67;&#x6d;&#97;&#x69;&#x6c;&#x2e;&#99;&#x6f;&#109;" data-bare-link="true">&#104;&#97;&#108;&#111;&#x73;&#x74;&#97;&#x74;&#117;&#101;&#x40;&#103;&#109;&#x61;&#x69;&#x6c;&#x2e;&#99;&#111;&#x6d;</a>&gt;</p>
<p>Written by Jesús Espino &lt;<a href="&#109;&#x61;&#x69;&#x6c;&#116;&#x6f;&#58;&#106;&#x65;&#x73;&#112;&#x69;&#x6e;&#111;&#x67;&#64;&#103;&#109;&#97;&#105;&#x6c;&#x2e;&#x63;&#111;&#x6d;" data-bare-link="true">&#x6a;&#101;&#x73;&#x70;&#105;&#110;&#x6f;&#x67;&#64;&#103;&#109;&#x61;&#x69;&#108;&#46;&#99;&#111;&#x6d;</a>&gt;<br />
Modified by Mark Pitman &lt;<a href="&#x6d;&#x61;&#x69;&#108;&#x74;&#x6f;&#58;&#x6d;&#97;&#x72;&#107;&#46;&#112;&#x69;&#116;&#x6d;&#97;&#x6e;&#64;&#x67;&#109;&#97;&#105;&#108;&#x2e;&#x63;&#111;&#x6d;" data-bare-link="true">&#x6d;&#x61;&#114;&#107;&#46;&#x70;&#105;&#x74;&#109;&#x61;&#x6e;&#64;&#103;&#x6d;&#x61;&#x69;&#x6c;&#x2e;&#99;&#x6f;&#109;</a>&gt;<br />
Modified by Carlos Prado &lt;<a href="&#109;&#x61;&#x69;&#108;&#x74;&#x6f;&#x3a;&#99;&#97;&#114;&#x6c;&#x6f;&#x73;&#x2e;&#x70;&#114;&#97;&#100;&#x6f;&#x40;&#x63;&#x70;&#x72;&#x61;&#100;&#111;&#103;&#46;&#x63;&#x6f;&#109;" data-bare-link="true">&#x63;&#97;&#x72;&#108;&#x6f;&#x73;&#x2e;&#x70;&#x72;&#97;&#100;&#111;&#x40;&#99;&#x70;&#x72;&#97;&#x64;&#111;&#x67;&#x2e;&#99;&#111;&#109;</a>&gt;<br />
Modified by Austin Ziegler &lt;<a href="&#109;&#x61;&#105;&#108;&#116;&#x6f;&#x3a;&#x68;&#97;&#108;&#x6f;&#x73;&#x74;&#x61;&#x74;&#117;&#x65;&#x40;&#103;&#109;&#x61;&#x69;&#x6c;&#x2e;&#x63;&#111;&#109;" data-bare-link="true">&#104;&#97;&#x6c;&#111;&#115;&#116;&#97;&#x74;&#117;&#x65;&#64;&#x67;&#x6d;&#97;&#x69;&#x6c;&#46;&#99;&#111;&#109;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -189,12 +193,12 @@ Modified by Austin Ziegler &lt;<a href="&#109;&#x61;&#105;&#108;&#x74;&#111;&#58
<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>
<p>&lt;<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>&gt;, <a class="man-ref" href="git-create-branch.html">git-create-branch<span class="s">(1)</span></a>, <a class="man-ref" href="git-delete-branch.html">git-delete-branch<span class="s">(1)</span></a></p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>September 2023</li>
<li class='tc'>December 2023</li>
<li class='tr'>git-feature(1)</li>
</ol>

View file

@ -1,4 +1,5 @@
# git-feature(1) -- Create/Merge feature branch
git-feature(1) -- Create/Merge feature branch
========================================================
## SYNOPSIS
@ -106,8 +107,8 @@ You can configure the default branch prefix and separator via git config options
$ git feature -- finish remote
...
$ (feature/finish-remote) git commit -m "Some changes"
$ (feature/finish-remote) git checkout main
$ (feature/finish-remote) git commit -m "Some changes"
$ (feature/finish-remote) git checkout main
$ git feature finish -- finish remote
## AUTHOR