Skip to contentSkip to conversation

Add -v option to git-branch.sh

PATCH New Lars Hjemli 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add -v option to git-branch.sh

Teach git-branch to show sha1 and subject for each branch tip.

This requires branch names to be max 20 chars for the output to be properly aligned. Not optimal, but doing an extra pass just to find the longest name didn't seem reasonable either.

---
 git-branch.sh |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
git-branch.sh +12 -2
index 4379a07..6a425e0 100755
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'
+USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r | -v'
 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>.'
@@ -56,6 +56,7 @@ ls_remote_branches () {
 
 force=
 create_log=
+verbose=
 while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
 do
 	case "$1" in
@@ -73,6 +74,9 @@ do
 	-l)
 		create_log="yes"
 		;;
+	-v)
+		verbose="yes"
+		;;
 	--)
 		shift
 		break
@@ -96,7 +100,13 @@ case "$#" in
 		else
 			pfx=' '
 		fi
-		echo "$pfx $ref"
+		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
 	exit 0 ;;
 1)
Signature · 1 line
1.4.3.ge193