summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/user-manual.txt2
-rw-r--r--builtin/checkout.c10
-rwxr-xr-xt/t2020-checkout-detach.sh123
3 files changed, 132 insertions, 3 deletions
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index 497e82e..eff7890 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -319,7 +319,7 @@ do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
-HEAD is now at 427abfa... Linux v2.6.17
+HEAD is now at 427abfa Linux v2.6.17
------------------------------------------------
The HEAD then refers to the SHA-1 of the commit instead of to a branch,
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 6c2b4cd..6a6f5bc 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -400,10 +400,16 @@ static void show_local_changes(struct object *head,
static void describe_detached_head(const char *msg, struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;
+
if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
- fprintf(stderr, "%s %s... %s\n", msg,
- find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
+ if (print_sha1_ellipsis()) {
+ fprintf(stderr, "%s %s... %s\n", msg,
+ find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
+ } else {
+ fprintf(stderr, "%s %s %s\n", msg,
+ find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
+ }
strbuf_release(&sb);
}
diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh
index fbb4ee9..9464069 100755
--- a/t/t2020-checkout-detach.sh
+++ b/t/t2020-checkout-detach.sh
@@ -186,4 +186,127 @@ test_expect_success 'no advice given for explicit detached head state' '
test_cmp expect.no-advice actual
'
+# Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (new format)
+test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not asked to' "
+
+ # The first detach operation is more chatty than the following ones.
+ cat >1st_detach <<-'EOF' &&
+ Note: checking out 'HEAD^'.
+
+ You are in 'detached HEAD' state. You can look around, make experimental
+ changes and commit them, and you can discard any commits you make in this
+ state without impacting any branches by performing another checkout.
+
+ If you want to create a new branch to retain commits you create, you may
+ do so (now or later) by using -b with the checkout command again. Example:
+
+ git checkout -b <new-branch-name>
+
+ HEAD is now at 7c7cd714e262 three
+ EOF
+
+ # The remaining ones just show info about previous and current HEADs.
+ cat >2nd_detach <<-'EOF' &&
+ Previous HEAD position was 7c7cd714e262 three
+ HEAD is now at 139b20d8e6c5 two
+ EOF
+
+ cat >3rd_detach <<-'EOF' &&
+ Previous HEAD position was 139b20d8e6c5 two
+ HEAD is now at d79ce1670bdc one
+ EOF
+
+ reset &&
+ check_not_detached &&
+
+ # Various ways of *not* asking for ellipses
+
+ sane_unset GIT_PRINT_SHA1_ELLIPSIS &&
+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 1st_detach actual &&
+
+ GIT_PRINT_SHA1_ELLIPSIS="no" git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 2nd_detach actual &&
+
+ GIT_PRINT_SHA1_ELLIPSIS= git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 3rd_detach actual &&
+
+ sane_unset GIT_PRINT_SHA1_ELLIPSIS &&
+
+ # We only have four commits, but we can re-use them
+ reset &&
+ check_not_detached &&
+
+ # Make no mention of the env var at all
+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 1st_detach actual &&
+
+ GIT_PRINT_SHA1_ELLIPSIS='nope' &&
+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 2nd_detach actual &&
+
+ GIT_PRINT_SHA1_ELLIPSIS=nein &&
+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 3rd_detach actual &&
+
+ true
+"
+
+# Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (old format)
+test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked to' "
+
+ # The first detach operation is more chatty than the following ones.
+ cat >1st_detach <<-'EOF' &&
+ Note: checking out 'HEAD^'.
+
+ You are in 'detached HEAD' state. You can look around, make experimental
+ changes and commit them, and you can discard any commits you make in this
+ state without impacting any branches by performing another checkout.
+
+ If you want to create a new branch to retain commits you create, you may
+ do so (now or later) by using -b with the checkout command again. Example:
+
+ git checkout -b <new-branch-name>
+
+ HEAD is now at 7c7cd714e262... three
+ EOF
+
+ # The remaining ones just show info about previous and current HEADs.
+ cat >2nd_detach <<-'EOF' &&
+ Previous HEAD position was 7c7cd714e262... three
+ HEAD is now at 139b20d8e6c5... two
+ EOF
+
+ cat >3rd_detach <<-'EOF' &&
+ Previous HEAD position was 139b20d8e6c5... two
+ HEAD is now at d79ce1670bdc... one
+ EOF
+
+ reset &&
+ check_not_detached &&
+
+ # Various ways of asking for ellipses...
+ # The user can just use any kind of quoting (including none).
+
+ GIT_PRINT_SHA1_ELLIPSIS="yes" git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 1st_detach actual &&
+
+ GIT_PRINT_SHA1_ELLIPSIS='yes' git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 2nd_detach actual &&
+
+ GIT_PRINT_SHA1_ELLIPSIS=yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
+ check_detached &&
+ test_i18ncmp 3rd_detach actual &&
+
+ true
+"
+
test_done