From 808213ba36ea72408cc45117a825ad9a714535ba Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Fri, 25 Feb 2022 23:12:13 -0700 Subject: switch: mention the --detach option when dying due to lack of a branch Users who are accustomed to doing `git checkout ` assume that `git switch ` 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 Signed-off-by: Junio C Hamano --- t/t2060-switch.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 't/t2060-switch.sh') 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 && -- cgit v1.2.3