e2db07859b36d752bb0784918f9e1571a150a4f8
   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 refuses to checkout locked branch' '
  21        test_must_fail git checkout --to zere master &&
  22        ! test -d zere &&
  23        ! test -d .git/worktrees/zere
  24'
  25
  26test_expect_success 'checkout --to a new worktree' '
  27        git rev-parse HEAD >expect &&
  28        git checkout --detach --to here master &&
  29        (
  30                cd here &&
  31                test_cmp ../init.t init.t &&
  32                test_must_fail git symbolic-ref HEAD &&
  33                git rev-parse HEAD >actual &&
  34                test_cmp ../expect actual &&
  35                git fsck
  36        )
  37'
  38
  39test_expect_success 'checkout --to a new worktree from a subdir' '
  40        (
  41                mkdir sub &&
  42                cd sub &&
  43                git checkout --detach --to here master &&
  44                cd here &&
  45                test_cmp ../../init.t init.t
  46        )
  47'
  48
  49test_expect_success 'checkout --to from a linked checkout' '
  50        (
  51                cd here &&
  52                git checkout --detach --to nested-here master &&
  53                cd nested-here &&
  54                git fsck
  55        )
  56'
  57
  58test_expect_success 'checkout --to a new worktree creating new branch' '
  59        git checkout --to there -b newmaster master &&
  60        (
  61                cd there &&
  62                test_cmp ../init.t init.t &&
  63                git symbolic-ref HEAD >actual &&
  64                echo refs/heads/newmaster >expect &&
  65                test_cmp expect actual &&
  66                git fsck
  67        )
  68'
  69
  70test_expect_success 'die the same branch is already checked out' '
  71        (
  72                cd here &&
  73                test_must_fail git checkout newmaster
  74        )
  75'
  76
  77test_expect_success 'not die on re-checking out current branch' '
  78        (
  79                cd there &&
  80                git checkout newmaster
  81        )
  82'
  83
  84test_done