From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/5] prompt: clean up describe logic
Date: Tue, 18 Jun 2013 22:43:24 +0530 [thread overview]
Message-ID: <1371575608-9980-2-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1371575608-9980-1-git-send-email-artagnon@gmail.com>
The describe logic is convoluted and unclean:
1. Reading .git/HEAD by hand and using the first 7 characters, of the
SHA-1 does not guarantee an unambiguous output; we can use rev-parse
--short in its place to get a unique SHA-1.
2. Use the --always option of describe to automatically output the short
SHA-1 when everything else fails.
The patch introduces one small change: since we are not checking the
return value of describe (with --always, it always returns something
valid), we cannot discriminate a raw SHA-1 from everything else and
suffix it with a "...".
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
contrib/completion/git-prompt.sh | 16 +++++++---------
t/t9903-bash-prompt.sh | 2 +-
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 86a4f3f..9ed6ff1 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -380,20 +380,18 @@ __git_ps1 ()
test -n "$b" ||
b="$(git symbolic-ref HEAD 2>/dev/null)" || {
detached=yes
- b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in
(contains)
- git describe --contains HEAD ;;
+ b=$(git describe --always --contains HEAD) ;;
(branch)
- git describe --contains --all HEAD ;;
+ b=$(git describe --always --contains --all HEAD) ;;
(describe)
- git describe HEAD ;;
+ b=$(git describe --always HEAD) ;;
(* | default)
- git describe --tags --exact-match HEAD ;;
- esac 2>/dev/null)" ||
-
- b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
- b="unknown"
+ b=$(git describe --tags --exact-match HEAD 2>/dev/null)
+ test -z $b && b="$(git rev-parse --short HEAD)"
+ ;;
+ esac
b="($b)"
}
fi
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 15521cc..b0ad477 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -169,7 +169,7 @@ test_expect_success 'prompt - branch name' '
'
test_expect_success 'prompt - detached head' '
- printf " ((%s...))" $(git log -1 --format="%h" b1^) > expected &&
+ printf " ((%s))" $(git log -1 --format="%h" b1^) > expected &&
git checkout b1^ &&
test_when_finished "git checkout master" &&
__git_ps1 > "$actual" &&
--
1.8.3.1.456.gb7f4cb6.dirty
next prev parent reply other threads:[~2013-06-18 17:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-18 17:13 [PATCH 0/5] Fix describe --contains --all Ramkumar Ramachandra
2013-06-18 17:13 ` Ramkumar Ramachandra [this message]
2013-06-18 17:13 ` [PATCH 2/5] prompt: do not double-discriminate detached HEAD Ramkumar Ramachandra
2013-06-18 17:13 ` [PATCH 3/5] name-rev: fix assumption about --name-only usage Ramkumar Ramachandra
2013-06-18 17:13 ` [PATCH 4/5] name-rev: strip trailing ^0 in when --name-only Ramkumar Ramachandra
2013-06-18 17:13 ` [PATCH 5/5] name-rev doc: rewrite --stdin paragraph Ramkumar Ramachandra
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=1371575608-9980-2-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).