Extend git-branch list output
cover Extend git-branch list output
This patch-series is on top of my previous patch to git-branch.sh
Shortlog:
[PATCH 1/3] Make git-branch honor -v when showing remote branches [PATCH 2/3] git-branch: Add -w option to adjust branchname column width [PATCH 3/3] Update documentation for git-branch
Diffstat:
Documentation/git-branch.txt | 8 ++++- git-branch.sh | 79 +++++++++++++++++++++++++++-------------- 2 files changed, 59 insertions(+), 28 deletions(-)
PATCH 1/3 Make git-branch honor -v when showing remote branches
Signed-off-by Lars Hjemli <[email protected]>
--- git-branch.sh | 74 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 47 insertions(+), 27 deletions(-)
git-branch.sh +47 -27
@@ -1,6 +1,6 @@ #!/bin/sh -USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r | -v' +USAGE='[-r] [-v] | (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>]' LONG_USAGE='If no arguments, show available branches and mark current branch with a star. If one argument, create a new branch <branchname> based off of current HEAD. If two arguments, create a new branch <branchname> based off of <start-point>.'
@@ -48,15 +48,48 @@ If you are sure you want to delete it, r exit 0 } -ls_remote_branches () { - git-rev-parse --symbolic --all | - sed -ne 's|^refs/\(remotes/\)|\1|p' | - sort -} - force= create_log= verbose= +remotes= + +ls_remote_branches () { + git-rev-parse --symbolic --all | + sed -ne 's|^refs/\(remotes/\)|\1|p' | + sort | + while read ref + do + if test "$verbose" = "yes" + then + log=$(git-log --max-count=1 --pretty=oneline $ref) + printf "%-20s %s\n" "$ref" "$log" + else + echo "$ref" + fi + done +} + +ls_local_branches() { + git-rev-parse --symbolic --branches | + sort | + while read ref + do + if test "$headref" = "$ref" + then + pfx='*' + else + pfx=' ' + fi + if test "$verbose" = "yes" + then + log=$(git-log --max-count=1 --pretty=oneline $ref) + printf "%s %-20s %s\n" "$pfx" "$ref" "$log" + else + echo "$pfx $ref" + fi + done +} + while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac do case "$1" in
@@ -65,8 +98,7 @@ do exit ;; -r) - ls_remote_branches - exit + remotes="yes" ;; -f) force="$1"
@@ -90,24 +122,12 @@ done case "$#" in 0) - git-rev-parse --symbolic --branches | - sort | - while read ref - do - if test "$headref" = "$ref" - then - pfx='*' - else - pfx=' ' - fi - if test "$verbose" = "yes" - then - log=$(git-log --max-count=1 --pretty=oneline $ref) - printf "%s %-20s %s\n" "$pfx" "$ref" "$log" - else - echo "$pfx $ref" - fi - done + if test "$remotes" = "yes" + then + ls_remote_branches + else + ls_local_branches + fi exit 0 ;; 1) head=HEAD ;;
Signature · 1 line
1.4.3.1
PATCH 2/3 git-branch: Add -w option to adjust branchname column width
In reply to Lars HjemliSigned-off-by Lars Hjemli <[email protected]>
--- git-branch.sh | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
git-branch.sh +8 -3
@@ -1,6 +1,6 @@ #!/bin/sh -USAGE='[-r] [-v] | (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>]' +USAGE='[-r] [-v [-w <width>]] | (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>]' LONG_USAGE='If no arguments, show available branches and mark current branch with a star. If one argument, create a new branch <branchname> based off of current HEAD. If two arguments, create a new branch <branchname> based off of <start-point>.'
@@ -52,6 +52,7 @@ force= create_log= verbose= remotes= +width=20 ls_remote_branches () { git-rev-parse --symbolic --all |
@@ -62,7 +63,7 @@ ls_remote_branches () { if test "$verbose" = "yes" then log=$(git-log --max-count=1 --pretty=oneline $ref) - printf "%-20s %s\n" "$ref" "$log" + printf "%-*s %s\n" "$width" "$ref" "$log" else echo "$ref" fi
@@ -83,7 +84,7 @@ ls_local_branches() { if test "$verbose" = "yes" then log=$(git-log --max-count=1 --pretty=oneline $ref) - printf "%s %-20s %s\n" "$pfx" "$ref" "$log" + printf "%s %-*s %s\n" "$pfx" "$width" "$ref" "$log" else echo "$pfx $ref" fi
@@ -108,6 +109,10 @@ do ;; -v) verbose="yes" + ;; + -w) + shift + width="$1" ;; --) shift
Signature · 1 line
1.4.3.1
PATCH 3/3 Update documentation for git-branch
In reply to Lars HjemliSigned-off-by Lars Hjemli <[email protected]>
--- Documentation/git-branch.txt | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
Documentation/git-branch.txt +7 -1
@@ -8,7 +8,7 @@ git-branch - List, create, or delete bra SYNOPSIS -------- [verse] -'git-branch' [-r] +'git-branch' [-r] [-v [-w <width>]] 'git-branch' [-l] [-f] <branchname> [<start-point>] 'git-branch' (-d | -D) <branchname>...
@@ -47,6 +47,12 @@ OPTIONS -r:: List only the "remote" branches. +-v:: + Show sha1 and first line of commit message for each branch + +-w <width>:: + Set columnwidth for branchname (default is 20) + <branchname>:: The name of the branch to create or delete. The new branch name must pass all checks defined by
Signature · 1 line
1.4.3.1