diff options
author | Julien Carsique <julien.carsique@gmail.com> | 2013-10-10 16:40:39 +0200 |
---|---|---|
committer | Jonathan Nieder <jrnieder@gmail.com> | 2013-10-14 10:24:34 -0700 |
commit | 1f6806cf2da84e30d162ca3aee15d16db4f1daef (patch) | |
tree | 04cad91545b03b27c291912029f7df911a7c41b3 | |
parent | c5f424fd014488bd8a92b97f52bfe47823bc2128 (diff) | |
download | git-1f6806cf2da84e30d162ca3aee15d16db4f1daef.tar.gz |
git-prompt.sh: optionally show upstream branch namejc/prompt-upstream
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>
Improved-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
-rw-r--r-- | contrib/completion/git-prompt.sh | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index d6c61b2bde..202e2e520f 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="$p $(git rev-parse --abbrev-ref "$upstream" 2>/dev/null)" + fi fi } |