submodule.c: report the submodule that an error occurs in
[gitweb.git] / t / t2020-checkout-detach.sh
index 5d68729d7a65abde09d1293e8569b730d2ba9a40..bb4f2e0c631f1de7421f50b9fa64f11276fe9645 100755 (executable)
@@ -163,4 +163,150 @@ test_expect_success 'tracking count is accurate after orphan check' '
        test_i18ncmp expect stdout
 '
 
+test_expect_success 'no advice given for explicit detached head state' '
+       # baseline
+       test_config advice.detachedHead true &&
+       git checkout child && git checkout HEAD^0 >expect.advice 2>&1 &&
+       test_config advice.detachedHead false &&
+       git checkout child && git checkout HEAD^0 >expect.no-advice 2>&1 &&
+       test_unconfig advice.detachedHead &&
+       # without configuration, the advice.* variables default to true
+       git checkout child && git checkout HEAD^0 >actual 2>&1 &&
+       test_cmp expect.advice actual &&
+
+       # with explicit --detach
+       # no configuration
+       test_unconfig advice.detachedHead &&
+       git checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&
+       test_cmp expect.no-advice actual &&
+
+       # explicitly decline advice
+       test_config advice.detachedHead false &&
+       git checkout child && git checkout --detach HEAD^0 >actual 2>&1 &&
+       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