From 9049967232d01882dc7d9941d0ee5d08053a786f Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Fri, 15 Dec 2023 20:05:52 -0800 Subject: [PATCH] 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 --- Commands.md | 7 ++++ bin/git-brv | 21 +++++++++- etc/bash_completion.sh | 4 ++ etc/git-extras-completion.zsh | 5 +++ etc/git-extras.fish | 2 + man/git-brv.1 | 25 +++++++++++- man/git-brv.html | 18 ++++++++- man/git-brv.md | 13 +++++- man/git-feature.1 | 10 ++++- man/git-feature.html | 76 ++++++++++++++++++----------------- man/git-feature.md | 7 ++-- 11 files changed, 141 insertions(+), 47 deletions(-) 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 @@

NAME

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

@@ -90,6 +97,13 @@

EXAMPLES

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

Written by Øsse <https://github.com/Osse>

@@ -105,7 +119,7 @@

SEE ALSO

  1. -
  2. January 2020
  3. +
  4. December 2023
  5. git-brv(1)
diff --git a/man/git-brv.md b/man/git-brv.md index 562a0a75a..2e03d0d48 100644 --- a/man/git-brv.md +++ b/man/git-brv.md @@ -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 diff --git a/man/git-feature.1 b/man/git-feature.1 index c448ec5c4..98fd4a7f5 100644 --- a/man/git-feature.1 +++ b/man/git-feature.1 @@ -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> . diff --git a/man/git-feature.html b/man/git-feature.html index 16a201b34..5796b18ee 100644 --- a/man/git-feature.html +++ b/man/git-feature.html @@ -77,56 +77,58 @@

NAME

SYNOPSIS

-

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...

-

DESCRIPTION

- -

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...

-

OPTIONS

- -

<-a|--alias branch_prefix>

+

DESCRIPTION

-

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]>

+

OPTIONS

-

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 finishing a branch.

+
finish:

-

<--squash>

+

Merge and delete the feature branch.

+
--squash:

-

Run a squash merge.

+

Run a squash merge when finishing the feature branch.

+
NAME:

-

<name>

+

The name of the feature branch.

+
-

The name of the feature branch.

GIT CONFIG

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 /.

EXAMPLES

@@ -168,20 +170,22 @@

EXAMPLES

$ (features.dependency-tracking) ...
$ (features.dependency-tracking) git checkout master
$ git feature finish dependency tracking

-
Use a git-feature option flag as part of a branch name:

+
Use a 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"

+$ (feature/finish-remote) git commit -m "Some changes"
+$ (feature/finish-remote) git checkout main
+$ git feature finish -- finish remote

AUTHOR

-

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>

REPORTING BUGS

@@ -189,12 +193,12 @@

REPORTING BUGS

SEE ALSO

-

<https://github.com/tj/git-extras>

+

<https://github.com/tj/git-extras>, git-create-branch(1), git-delete-branch(1)

  1. -
  2. September 2023
  3. +
  4. December 2023
  5. git-feature(1)
diff --git a/man/git-feature.md b/man/git-feature.md index ca7372299..e1a999d6c 100644 --- a/man/git-feature.md +++ b/man/git-feature.md @@ -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