From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH] git-prompt: stop manually parsing HEAD
Date: Fri, 24 Nov 2023 12:37:06 +0100 [thread overview]
Message-ID: <cc902954f30c2faa92d1c5a4469f0dcc23e4acfe.1700825779.git.ps@pks.im> (raw)
[-- Attachment #1: Type: text/plain, Size: 1675 bytes --]
We're manually parsing the HEAD reference in git-prompt to figure out
whether it is a symbolic or direct reference. This makes it intimately
tied to the on-disk format we use to store references and will stop
working once we gain additional reference backends in the Git project.
Refactor the code to always use git-symbolic-ref(1) to read HEAD, which
is both simpler and compatible with alternate reference backends.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
contrib/completion/git-prompt.sh | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 2c030050ae..05de540e13 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -474,17 +474,10 @@ __git_ps1 ()
if [ -n "$b" ]; then
:
- elif [ -h "$g/HEAD" ]; then
- # symlink symbolic ref
- b="$(git symbolic-ref HEAD 2>/dev/null)"
else
- local head=""
- if ! __git_eread "$g/HEAD" head; then
- return $exit
- fi
- # is it a symbolic ref?
- b="${head#ref: }"
- if [ "$head" = "$b" ]; then
+ b="$(git symbolic-ref HEAD 2>/dev/null)"
+
+ if test -z "$b"; then
detached=yes
b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in
@@ -498,9 +491,14 @@ __git_ps1 ()
git describe HEAD ;;
(* | default)
git describe --tags --exact-match HEAD ;;
- esac 2>/dev/null)" ||
+ esac 2>/dev/null)"
+
+ if test -z "$b"; then
+ test -z "$short_sha" && return $exit
+
+ b="$short_sha..."
+ fi
- b="$short_sha..."
b="($b)"
fi
fi
--
2.43.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2023-11-24 11:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 11:37 Patrick Steinhardt [this message]
2023-11-24 18:09 ` [PATCH] git-prompt: stop manually parsing HEAD Eric Sunshine
2023-11-24 18:28 ` SZEDER Gábor
2023-12-01 7:34 ` Patrick Steinhardt
2024-01-04 8:21 ` [PATCH v2] git-prompt: stop manually parsing HEAD with unknown ref formats Patrick Steinhardt
2024-01-04 11:51 ` Oswald Buddenhagen
2024-01-04 14:47 ` Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cc902954f30c2faa92d1c5a4469f0dcc23e4acfe.1700825779.git.ps@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).