{"thread":{"id":"19267","subject":"[PATCH 1/2] completion: simplify \"current branch\" in __git_ps1()","startedAt":"2009-05-10T08:53:19Z","lastAt":"2009-05-10T08:53:19Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"113450","messageId":"7v1vqx2vb4.fsf@alter.siamese.dyndns.org","threadId":"19267","inReplyTo":null,"subject":"[PATCH 1/2] completion: simplify \"current branch\" in __git_ps1()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-10T08:53:19Z","receivedAt":"2009-05-10T08:53:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As I very often work on a detached HEAD, I found it pretty confusing\nwhen __git_ps1() said 'some-name'.  Did I create a branch with that name\nby mistake, or do I happen to be on a commit with that exact tag?\n\nThis patch fixes the issue by enclosing non branch names in a pair of\nparentheses when used to substitute %s token in __git_ps1() argument.\n\nIt also fixes a small bug where the branch part is left empty when\n.git/HEAD is unreadable for whatever reason.  The output now says\n\"(unknown)\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n contrib/completion/git-completion.bash |   15 ++++++++-------\n 1 files changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 1683e6d..ccc7e0d 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -106,13 +106,14 @@ __git_ps1 ()\n \t\t\tif [ -f \"$g/BISECT_LOG\" ]; then\n \t\t\t\tr=\"|BISECTING\"\n \t\t\tfi\n-\t\t\tif ! b=\"$(git symbolic-ref HEAD 2>/dev/null)\"; then\n-\t\t\t\tif ! b=\"$(git describe --exact-match HEAD 2>/dev/null)\"; then\n-\t\t\t\t\tif [ -r \"$g/HEAD\" ]; then\n-\t\t\t\t\t\tb=\"$(cut -c1-7 \"$g/HEAD\")...\"\n-\t\t\t\t\tfi\n-\t\t\t\tfi\n-\t\t\tfi\n+\n+\t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\" || {\n+\t\t\t\tb=\"$(git describe --exact-match HEAD 2>/dev/null)\" ||\n+\t\t\t\tb=\"$(cut -c1-7 \"$g/HEAD\" 2>/dev/null)...\" ||\n+\t\t\t\tb=\"unknown\"\n+\n+\t\t\t\tb=\"($b)\"\n+\t\t\t}\n \t\tfi\n \n \t\tlocal w\n-- \n1.6.3.9.g6345d\n"}]}