git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt

At the beginning of __git_ps1, right after determining that the function is running in pc mode, set PS1 to a plain (undecorated) prompt. This makes it possible to simply return early without having to set PS1 if the prompt should not be decorated. Signed-off-by: Richard Hansen <rhansen@bbn.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Richard Hansen committed Jan 6, 2015 at 20:22 UTC 76b43094007824e9b487302c87d77779deb4a295
1 file changed +4 -7
contrib/completion/git-prompt.sh
+4 -7
@@ -299,6 +299,10 @@ __git_ps1 ()
299 ps1pc_start="$1"
300 ps1pc_end="$2"
301 printf_format="${3:-$printf_format}"
302 + # set PS1 to a plain prompt so that we can
303 + # simply return early if the prompt should not
304 + # be decorated
305 + PS1="$ps1pc_start$ps1pc_end"
306 ;;
307 0|1) printf_format="${1:-$printf_format}"
308 ;;
@@ -350,10 +354,6 @@ __git_ps1 ()
354 rev_parse_exit_code="$?"
355
356 if [ -z "$repo_info" ]; then
353 - if [ $pcmode = yes ]; then
354 - #In PC mode PS1 always needs to be set
355 - PS1="$ps1pc_start$ps1pc_end"
356 - fi
357 return
358 fi
359
@@ -412,9 +412,6 @@ __git_ps1 ()
412 else
413 local head=""
414 if ! __git_eread "$g/HEAD" head; then
415 - if [ $pcmode = yes ]; then
416 - PS1="$ps1pc_start$ps1pc_end"
417 - fi
415 return
416 fi
417 # is it a symbolic ref?