git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] Make git-branch honor -v when showing remote branches

From
LHLars Hjemli <hjemli@gmail.com>
Date
Oct 21, 2006, 22:33 UTC
Message-ID
<11614700063520-git-send-email-hjemli@gmail.com>
In-Reply-To
<1161470004894-git-send-email-hjemli@gmail.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
 git-branch.sh |   74 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 47 insertions(+), 27 deletions(-)
diff --git a/git-branch.sh b/git-branch.sh
index ab58737..25abd4c 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -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 ;;
-- 
1.4.3.1
Previous: Lars HjemliNext: Lars Hjemli
Message 2 of 4 in “Extend git-branch list output”
  1. 0/3 Extend git-branch list outputLars Hjemli, Oct 21, 2006
  2. 1/3 Make git-branch honor -v when showing remote branchesLars Hjemli, Oct 21, 2006
  3. 2/3 git-branch: Add -w option to adjust branchname column widthLars Hjemli, Oct 21, 2006
  4. 3/3 Update documentation for git-branchLars Hjemli, Oct 21, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.