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

[PATCH] git-prompt.sh: show the upstream abbrev name

From
Julien Carsique <julien.carsique@gmail.com>
Date
Oct 10, 2013, 13:32 UTC
Message-ID
<1381411933-20600-1-git-send-email-jcarsique@nuxeo.com>
From: Julien Carsique <julien.carsique@gmail.com>

When working with multiple remotes, it is common to switch the upstream from a remote to another. Doing so, the prompt may not be the expected one. Providing an option to display tracking information sounds useful.

Add a "name" option to GIT_PS1_SHOWUPSTREAM which will show the upstream abbrev name. This option is ignored if "verbose" is false.

Signed-off-by: Julien Carsique <julien.carsique@gmail.com>
---
 contrib/completion/git-prompt.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index d6c61b2..452f7ee 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -60,6 +60,7 @@
 # of values:
 #
 #     verbose       show number of commits ahead/behind (+/-) upstream
+#     name          if verbose, then also show the upstream abbrev name
 #     legacy        don't use the '--count' option available in recent
 #                   versions of git-rev-list
 #     git           always compare HEAD to @{upstream}
@@ -94,7 +95,7 @@ __git_ps1_show_upstream ()
 {
 	local key value
 	local svn_remote svn_url_pattern count n
-	local upstream=git legacy="" verbose=""
+	local upstream=git legacy="" verbose="" name=""
 
 	svn_remote=()
 	# get some config options from git-config
@@ -122,6 +123,7 @@ __git_ps1_show_upstream ()
 		git|svn) upstream="$option" ;;
 		verbose) verbose=1 ;;
 		legacy)  legacy=1  ;;
+		name)   name=1 ;;
 		esac
 	done
 
@@ -204,6 +206,9 @@ __git_ps1_show_upstream ()
 		*)	    # diverged from upstream
 			p=" u+${count#*	}-${count%	*}" ;;
 		esac
+		if [[ -n "$count" && -n "$name" ]]; then
+			p+=" $(git rev-parse --abbrev-ref "$upstream" 2>/dev/null)"
+		fi
 	fi
 
 }
-- 
1.8.1.2
Next: SZEDER Gábor
Message 1 of 5 in “git-prompt.sh: show the upstream abbrev name”
  1. git-prompt.sh: show the upstream abbrev nameJulien Carsique, Oct 10, 2013
  2. SZEDER GáborOct 10, 2013
  3. git-prompt.sh: show the upstream abbrev nameJulien Carsique, Oct 10, 2013
  4. Julien CarsiqueOct 10, 2013
  5. SZEDER GáborOct 15, 2013

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.