aboutsummaryrefslogtreecommitdiffstats
path: root/t/t2400-worktree-add.sh
diff options
context:
space:
mode:
authorJacob Abel <jacobabel@nullpo.dev>2023-05-17 21:49:06 +0000
committerJunio C Hamano <gitster@pobox.com>2023-05-17 15:55:25 -0700
commit926c40d04b5a77e00d3b22a5d2696c22b81569cc (patch)
treebf2394393091da7dc48be67f970e6f53ba9e55f9 /t/t2400-worktree-add.sh
parent128e5496b325640f0a09cc1d5b1e346c069b410f (diff)
downloadgit-926c40d04b5a77e00d3b22a5d2696c22b81569cc.tar.gz
worktree add: emit warn when there is a bad HEAD
Add a warning to `worktree add` when the command tries to reference HEAD, there exist valid local branches, and the HEAD points to a non-existent reference. Current Behavior: % git -C foo worktree list /path/to/repo/foo dadc8e6dac [main] /path/to/repo/foo_wt 0000000000 [badref] % git -C foo worktree add ../wt1 Preparing worktree (new branch 'wt1') HEAD is now at dadc8e6dac dummy commit % git -C foo_wt worktree add ../wt2 hint: If you meant to create a worktree containing a new orphan branch [...] hint: Disable this message with "git config advice.worktreeAddOrphan false" fatal: invalid reference: HEAD % New Behavior: % git -C foo worktree list /path/to/repo/foo dadc8e6dac [main] /path/to/repo/foo_wt 0000000000 [badref] % git -C foo worktree add ../wt1 Preparing worktree (new branch 'wt1') HEAD is now at dadc8e6dac dummy commit % git -C foo_wt worktree add ../wt2 warning: HEAD points to an invalid (or orphaned) reference. HEAD path: '/path/to/repo/foo/.git/worktrees/foo_wt/HEAD' HEAD contents: 'ref: refs/heads/badref' hint: If you meant to create a worktree containing a new orphan branch [...] hint: Disable this message with "git config advice.worktreeAddOrphan false" fatal: invalid reference: HEAD % Signed-off-by: Jacob Abel <jacobabel@nullpo.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2400-worktree-add.sh')
-rwxr-xr-xt/t2400-worktree-add.sh18
1 files changed, 17 insertions, 1 deletions
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index c7ca8df586..0ac468e69e 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -722,6 +722,7 @@ test_dwim_orphan () {
local use_quiet=0 &&
local remote=0 &&
local remote_ref=0 &&
+ local use_detach=0 &&
local use_new_branch=0 &&
local outcome="$1" &&
@@ -747,6 +748,10 @@ test_dwim_orphan () {
success=0 &&
outcome_text='"add" error inferred "--orphan" gives illegal opts combo'
;;
+ "warn_bad_head")
+ success=0 &&
+ outcome_text='"add" error, warn on bad HEAD, hint use orphan'
+ ;;
*)
echo "test_dwim_orphan(): invalid outcome: '$outcome'" >&2 &&
return 1
@@ -818,7 +823,7 @@ test_dwim_orphan () {
context="$context, invalid (or orphan) HEAD"
;;
- # Whether the code path is tested with the base add command or -b
+ # Whether the code path is tested with the base add command, -b, or --detach
"no_-b")
use_new_branch=0 &&
context="$context, no --branch"
@@ -827,6 +832,10 @@ test_dwim_orphan () {
use_new_branch=1 &&
context="$context, --branch"
;;
+ "detach")
+ use_detach=1 &&
+ context="$context, --detach"
+ ;;
# Whether to check that all output is suppressed (except errors)
# or that the output is as expected
@@ -887,6 +896,9 @@ test_dwim_orphan () {
if [ $use_new_branch -eq 1 ]
then
args="$args -b foo"
+ elif [ $use_detach -eq 1 ]
+ then
+ args="$args --detach"
else
context="DWIM (no --branch), $context"
fi &&
@@ -1023,6 +1035,10 @@ do
test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref remote no_remote_ref no_guess_remote
test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref remote no_remote_ref guess_remote
test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref remote remote_ref guess_remote
+
+ test_dwim_orphan 'warn_bad_head' $dwim_test_args no_-b local_ref bad_head
+ test_dwim_orphan 'warn_bad_head' $dwim_test_args -b local_ref bad_head
+ test_dwim_orphan 'warn_bad_head' $dwim_test_args detach local_ref bad_head
done
test_dwim_orphan 'fatal_orphan_bad_combo' $quiet_mode no_-b no_checkout