Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reverse option to git-brv #1123

Merged
merged 5 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion bin/git-brv
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions etc/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ _git_authors(){
__gitcomp "-l --list --no-email"
}

_git_brv(){
__gitcomp "-r --reverse"
}

_git_coauthor(){
local oldIfs=$IFS
IFS=$'\n'
Expand Down
5 changes: 5 additions & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down
2 changes: 2 additions & 0 deletions etc/git-extras.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
25 changes: 23 additions & 2 deletions man/git-brv.1
Original file line number Diff line number Diff line change
@@ -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
.
Expand All @@ -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>
.
Expand Down
18 changes: 16 additions & 2 deletions man/git-brv.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/git-brv.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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

Expand Down
10 changes: 8 additions & 2 deletions man/git-feature.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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>
.
Expand Down
76 changes: 40 additions & 36 deletions man/git-feature.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/git-feature.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# git-feature(1) -- Create/Merge feature branch
git-feature(1) -- Create/Merge feature branch
========================================================

## SYNOPSIS

Expand Down Expand Up @@ -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
joshka marked this conversation as resolved.
Show resolved Hide resolved
$ git feature finish -- finish remote

## AUTHOR
Expand Down
Loading