* [PATCH] git-prompt.sh: show the upstream abbrev name
@ 2013-10-10 13:32 Julien Carsique
2013-10-10 13:58 ` SZEDER Gábor
0 siblings, 1 reply; 5+ messages in thread
From: Julien Carsique @ 2013-10-10 13:32 UTC (permalink / raw)
To: git
Cc: Julien Carsique, Junio C Hamano, SZEDER Gábor,
Ramkumar Ramachandra, Simon Oosthoek, Eduardo R . D'Avila,
Felipe Contreras
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] git-prompt.sh: show the upstream abbrev name
2013-10-10 13:32 [PATCH] git-prompt.sh: show the upstream abbrev name Julien Carsique
@ 2013-10-10 13:58 ` SZEDER Gábor
2013-10-10 14:40 ` Julien Carsique
2013-10-10 14:43 ` Julien Carsique
0 siblings, 2 replies; 5+ messages in thread
From: SZEDER Gábor @ 2013-10-10 13:58 UTC (permalink / raw)
To: Julien Carsique
Cc: git, Junio C Hamano, Ramkumar Ramachandra, Simon Oosthoek,
Eduardo R . D'Avila, Felipe Contreras
Hi,
On Thu, Oct 10, 2013 at 03:32:13PM +0200, Julien Carsique wrote:
> @@ -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)"
The '+=' operator is not supported in all Bash versions we care about.
Please write this as p="$p $(...)".
Thanks,
Gábor
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] git-prompt.sh: show the upstream abbrev name
2013-10-10 13:58 ` SZEDER Gábor
@ 2013-10-10 14:40 ` Julien Carsique
2013-10-10 14:43 ` Julien Carsique
1 sibling, 0 replies; 5+ messages in thread
From: Julien Carsique @ 2013-10-10 14:40 UTC (permalink / raw)
To: git
Cc: Julien Carsique, Junio C Hamano, SZEDER Gábor,
Ramkumar Ramachandra, Simon Oosthoek, Eduardo R . D'Avila,
Felipe Contreras
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>
Reviewed-by: SZEDER Gábor <szeder@ira.uka.de>
---
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..84cd3a8 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
}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] git-prompt.sh: show the upstream abbrev name
2013-10-10 13:58 ` SZEDER Gábor
2013-10-10 14:40 ` Julien Carsique
@ 2013-10-10 14:43 ` Julien Carsique
2013-10-15 12:21 ` SZEDER Gábor
1 sibling, 1 reply; 5+ messages in thread
From: Julien Carsique @ 2013-10-10 14:43 UTC (permalink / raw)
To: SZEDER Gábor
Cc: git, Junio C Hamano, Ramkumar Ramachandra, Simon Oosthoek,
Eduardo R . D'Avila, Felipe Contreras
On 10/10/2013 15:58, SZEDER Gábor wrote:
> Hi,
>
> On Thu, Oct 10, 2013 at 03:32:13PM +0200, Julien Carsique wrote:
>> @@ -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)"
> The '+=' operator is not supported in all Bash versions we care about.
> Please write this as p="$p $(...)".
>
> Thanks,
> Gábor
>
Hi,
It's fixed.
Note '+=' was already used line 114:
svn_url_pattern+="\\|$value"
Thank you for the review,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] git-prompt.sh: show the upstream abbrev name
2013-10-10 14:43 ` Julien Carsique
@ 2013-10-15 12:21 ` SZEDER Gábor
0 siblings, 0 replies; 5+ messages in thread
From: SZEDER Gábor @ 2013-10-15 12:21 UTC (permalink / raw)
To: Julien Carsique, Junio C Hamano
Cc: git, Ramkumar Ramachandra, Simon Oosthoek,
Eduardo R . D'Avila, Felipe Contreras
On Thu, Oct 10, 2013 at 04:43:22PM +0200, Julien Carsique wrote:
> It's fixed.
Thanks, the updated patch looks good to me.
> Note '+=' was already used line 114:
>
> svn_url_pattern+="\\|$value"
I guess noone has tried to use the upstream status indicator with an
SVN upstream and an ancient Bash version yet, thanks for pointing it
out.
-- >8 --
Subject: [PATCH] bash prompt: don't use '+=' operator in show upstream code path
The '+=' operator is not supported by old Bash versions (3.0) we still
care about.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
contrib/completion/git-prompt.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 202e2e520f..7b732d2aeb 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -111,7 +111,7 @@ __git_ps1_show_upstream ()
;;
svn-remote.*.url)
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
- svn_url_pattern+="\\|$value"
+ svn_url_pattern="$svn_url_pattern\\|$value"
upstream=svn+git # default upstream is SVN if available, else git
;;
esac
--
1.8.4.1.495.gd8d272e
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-10-15 12:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-10 13:32 [PATCH] git-prompt.sh: show the upstream abbrev name Julien Carsique
2013-10-10 13:58 ` SZEDER Gábor
2013-10-10 14:40 ` Julien Carsique
2013-10-10 14:43 ` Julien Carsique
2013-10-15 12:21 ` SZEDER Gábor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).