summaryrefslogtreecommitdiffstats
path: root/t/t2060-switch.sh
diff options
context:
space:
mode:
authorAlex Henrie <alexhenrie24@gmail.com>2022-02-26 07:12:13 +0100
committerJunio C Hamano <gitster@pobox.com>2022-02-26 07:21:48 +0100
commit808213ba36ea72408cc45117a825ad9a714535ba (patch)
tree46ce0e0ac916122d22dfe7ddd552c36beff5714d /t/t2060-switch.sh
parentThe seventh batch (diff)
downloadgit-808213ba36ea72408cc45117a825ad9a714535ba.tar.xz
git-808213ba36ea72408cc45117a825ad9a714535ba.zip
switch: mention the --detach option when dying due to lack of a branch
Users who are accustomed to doing `git checkout <tag>` assume that `git switch <tag>` will do the same thing. Inform them of the --detach option so they aren't left wondering why `git switch` doesn't work but `git checkout` does. Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rwxr-xr-xt/t2060-switch.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh
index ebb961be29..5a7caf958c 100755
--- a/t/t2060-switch.sh
+++ b/t/t2060-switch.sh
@@ -32,6 +32,17 @@ test_expect_success 'switch and detach' '
test_must_fail git symbolic-ref HEAD
'
+test_expect_success 'suggestion to detach' '
+ test_must_fail git switch main^{commit} 2>stderr &&
+ grep "try again with the --detach option" stderr
+'
+
+test_expect_success 'suggestion to detach is suppressed with advice.suggestDetachingHead=false' '
+ test_config advice.suggestDetachingHead false &&
+ test_must_fail git switch main^{commit} 2>stderr &&
+ ! grep "try again with the --detach option" stderr
+'
+
test_expect_success 'switch and detach current branch' '
test_when_finished git switch main &&
git switch main &&