summaryrefslogtreecommitdiff
path: root/t/t2020-checkout-detach.sh
diff options
context:
space:
mode:
authorAnn T Ropea <bedhanger@gmx.de>2017-12-06 00:20:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-06 15:32:40 (GMT)
commitca69d4d5b14245c9ba4535212c4f4a0621e78ffa (patch)
tree66a56fe0f738068bcfd6c63c8ce6d89cde27b225 /t/t2020-checkout-detach.sh
parenta2cd709de314a7bfa038e14fd36f1d21077b4173 (diff)
downloadgit-ca69d4d5b14245c9ba4535212c4f4a0621e78ffa.zip
git-ca69d4d5b14245c9ba4535212c4f4a0621e78ffa.tar.gz
git-ca69d4d5b14245c9ba4535212c4f4a0621e78ffa.tar.bz2
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>
Diffstat (limited to 't/t2020-checkout-detach.sh')
-rwxr-xr-xt/t2020-checkout-detach.sh123
1 files changed, 123 insertions, 0 deletions
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