diff --git a/Commands.md b/Commands.md index 04c6f2dcd..71c1275b5 100644 --- a/Commands.md +++ b/Commands.md @@ -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 diff --git a/bin/git-brv b/bin/git-brv index 7b46b12a4..8940089fd 100755 --- a/bin/git-brv +++ b/bin/git-brv @@ -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) diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index 6d4b3bdda..3fc1dcc21 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -26,6 +26,10 @@ _git_authors(){ __gitcomp "-l --list --no-email" } +_git_brv(){ + __gitcomp "-r --reverse" +} + _git_coauthor(){ local oldIfs=$IFS IFS=$'\n' diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 33c8c195b..a5cbd570e 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -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]' \ diff --git a/etc/git-extras.fish b/etc/git-extras.fish index 0a0b49d2e..b971fc119 100644 --- a/etc/git-extras.fish +++ b/etc/git-extras.fish @@ -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' diff --git a/man/git-brv.1 b/man/git-brv.1 index d49494c55..b0eaa1ab1 100644 --- a/man/git-brv.1 +++ b/man/git-brv.1 @@ -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> . diff --git a/man/git-brv.html b/man/git-brv.html index 8e265d9ae..ffcd3efea 100644 --- a/man/git-brv.html +++ b/man/git-brv.html @@ -56,6 +56,7 @@ NAME SYNOPSIS DESCRIPTION + OPTIONS EXAMPLES AUTHOR REPORTING BUGS @@ -75,12 +76,18 @@
git-brv
git-brv
[-r|--reverse]
Pretty listing of branches sorted by the date of their last commit.
+-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.
Simply run git brv
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
+
+
Written by Øsse <https://github.com/Osse>
@@ -105,7 +119,7 @@git-feature
[-a|--alias branch_prefix] [-s|--separator branch_separator] [-r|--remote [remote_name]] <name>
-git-feature
[-a|--alias branch_prefix] [-s|--separator branch_separator] finish [--squash] <name>
git-feature
[-a|--alias PREFIX] [-s|--separator SEPARATOR] [-r|--remote [REMOTE_NAME]] [--from START_POINT] NAME...
Create/Merge the given feature branch.
- -The branch name
may be specified as multiple words which will be joined with -
characters. If any word should start with a -
, the name should be preceded by --
, which will signal that option parsing should be ignored.
git-feature
[-a|--alias PREFIX] [-s|--separator SEPARATOR] finish [--squash] NAME...
<-a|--alias branch_prefix>
+The branch prefix to use, or feature
if not supplied.
Create or merge the given feature branch. The feature branch name is made from the PREFIX, the SEPARATOR, and the NAME joined together.
-<-s|--separator branch_separator>
+The default PREFIX is feature
and SEPARATOR is /
, which can be changed (see OPTIONS and GIT CONFIG for details).
The separator to use for joining the branch prefix and the branch name, or /
if not supplied.
The branch NAME may be specified as multiple words which will be joined with -
. If the branch name contains the word finish
or is another OPTION, --
should be passed to stop OPTION parsing. See the EXAMPLES for details.
<-r|--remote [remote_name]>
+Setup a remote tracking branch using remote_name
. If remote_name
is not supplied, use origin
by default.
-a
PREFIX, --alias
PREFIX:<--from [start_point]>
+The branch prefix to use, or feature
if not supplied.
-s
SEPARATOR, --separator
SEPARATOR:Setup a start point when the branch created. If --from
is not supplied, use the current branch by default.
The separator to use for joining the branch prefix and the branch name, or /
if not supplied.
-r
[REMOTE_NAME], --remote
[REMOTE_NAME]:<finish>
+Setup a remote tracking branch using remote_name
. If remote_name
is not supplied, use origin
by default.
--from
START_POINT:Merge and delete the feature branch.
+Setup a start point when the branch created. If --from
is not supplied, use the current branch by default. This option will be ignored when finish
ing a branch.
finish
:<--squash>
+Merge and delete the feature branch.
--squash
:Run a squash merge.
+Run a squash merge when finish
ing the feature branch.
<name>
+The name of the feature branch.
The name of the feature branch.
You can configure the default branch prefix and separator via git config options.
-$ git config --global add git-extras.feature.prefix "branch_prefix"
+git-extras.feature.prefix
:The default branch_prefix
is feature
.
$ git config --global add git-extras.feature.prefix "prefix"
git-extras.feature.separator
:$ git config --global add git-extras.feature.separator "-"
+$ git config --global add git-extras.feature.separator "-"
The default branch_separator
is /
.
git-feature
option flag as part of a branch name:git-feature
option or the finish
command as part of a branch name:$ git feature -- --remote
+
$ git feature -- finish remote
...
-$ (feature/--remote) git commit -m "Some changes"
Written by Jesús Espino <jespinog@gmail.com>
-Modified by Mark Pitman <mark.pitman@gmail.com>
-Modified by Carlos Prado <carlos.prado@cpradog.com>
-Modified by Austin Ziegler <halostatue@gmail.com>
Written by Jesús Espino <jespinog@gmail.com>
+Modified by Mark Pitman <mark.pitman@gmail.com>
+Modified by Carlos Prado <carlos.prado@cpradog.com>
+Modified by Austin Ziegler <halostatue@gmail.com>
<https://github.com/tj/git-extras>
+<https://github.com/tj/git-extras>, git-create-branch(1), git-delete-branch(1)