checkout: describe_detached_head: remove ellipsis after committish

We do not want an ellipsis displayed following an (abbreviated) SHA-1
value.

The days when this was necessary to indicate the truncation to
lower-level Git commands and/or the user are bygone.

However, to ease the transition, the ellipsis will still be printed if
the user sets the environment variable GIT_PRINT_SHA1_ELLIPSIS to "yes".

Correct documentation with respect to what describe_detached_head prints
when GIT_PRINT_SHA1_ELLIPSIS is not set as indicated above.

Add tests for the old and new behaviour.

Signed-off-by: Ann T Ropea <bedhanger@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ann T Ropea 2017-12-06 01:20:42 +01:00 коммит произвёл Junio C Hamano
Родитель a2cd709de3
Коммит ca69d4d5b1
3 изменённых файлов: 132 добавлений и 3 удалений

Просмотреть файл

@ -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,

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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