t / t2025-checkout-to.shon commit checkout: reject if the branch is already checked out elsewhere (5883034)
   1#!/bin/sh
   2
   3test_description='test git checkout --to'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_commit init
   9'
  10
  11test_expect_success 'checkout --to not updating paths' '
  12        test_must_fail git checkout --to -- init.t
  13'
  14
  15test_expect_success 'checkout --to an existing worktree' '
  16        mkdir existing &&
  17        test_must_fail git checkout --detach --to existing master
  18'
  19
  20test_expect_success 'checkout --to a new worktree' '
  21        git rev-parse HEAD >expect &&
  22        git checkout --detach --to here master &&
  23        (
  24                cd here &&
  25                test_cmp ../init.t init.t &&
  26                test_must_fail git symbolic-ref HEAD &&
  27                git rev-parse HEAD >actual &&
  28                test_cmp ../expect actual &&
  29                git fsck
  30        )
  31'
  32
  33test_expect_success 'checkout --to a new worktree from a subdir' '
  34        (
  35                mkdir sub &&
  36                cd sub &&
  37                git checkout --detach --to here master &&
  38                cd here &&
  39                test_cmp ../../init.t init.t
  40        )
  41'
  42
  43test_expect_success 'checkout --to from a linked checkout' '
  44        (
  45                cd here &&
  46                git checkout --detach --to nested-here master &&
  47                cd nested-here &&
  48                git fsck
  49        )
  50'
  51
  52test_expect_success 'checkout --to a new worktree creating new branch' '
  53        git checkout --to there -b newmaster master &&
  54        (
  55                cd there &&
  56                test_cmp ../init.t init.t &&
  57                git symbolic-ref HEAD >actual &&
  58                echo refs/heads/newmaster >expect &&
  59                test_cmp expect actual &&
  60                git fsck
  61        )
  62'
  63
  64test_expect_success 'die the same branch is already checked out' '
  65        (
  66                cd here &&
  67                test_must_fail git checkout newmaster
  68        )
  69'
  70
  71test_expect_success 'not die on re-checking out current branch' '
  72        (
  73                cd there &&
  74                git checkout newmaster
  75        )
  76'
  77
  78test_done