[PATCH 05/19] bash prompt: don't show the prompt when .git/HEAD is unreadable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



__git_ps1() has a chain of commands to figure out what to display in
the prompt as current branch, i.e. the branch name, or a described
detached head, or the 7 hexdigits abbreviated object name, or
"(unknown)" when all of the above fails.

Now, when the 7 hexdigits case fails, then '/path/to/.git/HEAD' can't
be read.  This can happen when the file became unreadable after
__gitdir() found it: unlikely, but a parallel process can racily
delete it or change it's permissions in that short timeframe.
Alternatively, it is possible that either the subshell or the 'cut'
command fail.  Either way, when HEAD is not readable, then the path is
not considered to be a git repository, therefore the bash prompt
shouldn't be displayed at all.  And there is no point in continuing
the execution of __git_ps1(), because its subsequent git commands will
error out anyway.

Signed-off-by: SZEDER Gábor <szeder@xxxxxxxxxx>
---
 contrib/completion/git-completion.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index ab26bdc8..cd6a5f12 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -258,7 +258,7 @@ __git_ps1 ()
 				esac 2>/dev/null)" ||
 
 				b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
-				b="unknown"
+				return
 				b="($b)"
 			}
 		fi
-- 
1.7.10.1.541.gb1be298

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]