@@ -420,31 +420,68 @@ func TestE2E_CreateWorktree(t *testing.T) {
420420 }
421421 })
422422
423- t .Run ("start_point_ignored_for_existing_branch " , func (t * testing.T ) {
423+ t .Run ("start_point_error_for_existing_branch " , func (t * testing.T ) {
424424 t .Parallel ()
425425 repo := testutil .NewTestRepo (t )
426426 repo .CreateFile ("README.md" , "# Test" )
427427 repo .Commit ("initial commit" )
428428
429429 repo .Git ("branch" , "existing-branch" )
430430
431- repo .CreateFile ("new-file.txt" , "new content" )
432- repo .Commit ("second commit" )
431+ _ , _ , err := runGitWtStdout (t , binPath , repo .Root , "existing-branch" , "main" )
432+ if err == nil {
433+ t .Fatal ("expected error when start-point is specified for existing branch, but got none" )
434+ }
435+ })
433436
434- stdout , stderr , err := runGitWtStdout (t , binPath , repo .Root , "existing-branch" , "main" )
435- if err != nil {
436- t .Fatalf ("git-wt failed: %v\n stderr: %s" , err , stderr )
437+ t .Run ("start_point_error_for_existing_worktree" , func (t * testing.T ) {
438+ t .Parallel ()
439+ repo := testutil .NewTestRepo (t )
440+ repo .CreateFile ("README.md" , "# Test" )
441+ repo .Commit ("initial commit" )
442+
443+ // Create worktree first
444+ if _ , err := runGitWt (t , binPath , repo .Root , "feature-branch" ); err != nil {
445+ t .Fatalf ("failed to create worktree: %v" , err )
437446 }
438447
439- wtPath := strings .TrimSpace (stdout )
440- if _ , err := os .Stat (wtPath ); os .IsNotExist (err ) {
441- t .Fatalf ("worktree was not created at %s" , wtPath )
448+ // Switching to existing worktree with start-point should error
449+ _ , _ , err := runGitWtStdout (t , binPath , repo .Root , "feature-branch" , "main" )
450+ if err == nil {
451+ t .Fatal ("expected error when start-point is specified for existing worktree, but got none" )
442452 }
453+ })
443454
444- // Verify the worktree is based on existing-branch (should NOT have new-file.txt)
445- newFilePath := filepath .Join (wtPath , "new-file.txt" )
446- if _ , err := os .Stat (newFilePath ); ! os .IsNotExist (err ) {
447- t .Error ("worktree should NOT have new-file.txt (start-point should be ignored for existing branch)" )
455+ t .Run ("start_point_error_for_existing_branch_with_b_flag" , func (t * testing.T ) {
456+ t .Parallel ()
457+ repo := testutil .NewTestRepo (t )
458+ repo .CreateFile ("README.md" , "# Test" )
459+ repo .Commit ("initial commit" )
460+
461+ repo .Git ("branch" , "existing-branch" )
462+
463+ // Creating worktree with -b for existing branch and start-point should error
464+ _ , _ , err := runGitWtStdout (t , binPath , repo .Root , "mydir" , "-b" , "existing-branch" , "main" )
465+ if err == nil {
466+ t .Fatal ("expected error when start-point is specified with -b for existing branch, but got none" )
467+ }
468+ })
469+
470+ t .Run ("start_point_error_for_existing_worktree_with_b_flag" , func (t * testing.T ) {
471+ t .Parallel ()
472+ repo := testutil .NewTestRepo (t )
473+ repo .CreateFile ("README.md" , "# Test" )
474+ repo .Commit ("initial commit" )
475+
476+ // Create worktree first
477+ if _ , err := runGitWt (t , binPath , repo .Root , "feature-branch" ); err != nil {
478+ t .Fatalf ("failed to create worktree: %v" , err )
479+ }
480+
481+ // Switching to existing worktree with -b and start-point should error
482+ _ , _ , err := runGitWtStdout (t , binPath , repo .Root , "feature-branch" , "-b" , "feature-branch" , "main" )
483+ if err == nil {
484+ t .Fatal ("expected error when start-point is specified with -b for existing worktree, but got none" )
448485 }
449486 })
450487
0 commit comments