eddd3251f1faede8cbfb0c9f6db501f0facfe063
   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_expect_success 'checkout --to from a bare repo' '
  85        (
  86                git clone --bare . bare &&
  87                cd bare &&
  88                git checkout --to ../there2 -b bare-master master
  89        )
  90'
  91
  92test_expect_success 'checkout from a bare repo without --to' '
  93        (
  94                cd bare &&
  95                test_must_fail git checkout master
  96        )
  97'
  98
  99test_expect_success 'checkout with grafts' '
 100        test_when_finished rm .git/info/grafts &&
 101        test_commit abc &&
 102        SHA1=`git rev-parse HEAD` &&
 103        test_commit def &&
 104        test_commit xyz &&
 105        echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
 106        cat >expected <<-\EOF &&
 107        xyz
 108        abc
 109        EOF
 110        git log --format=%s -2 >actual &&
 111        test_cmp expected actual &&
 112        git checkout --detach --to grafted master &&
 113        git --git-dir=grafted/.git log --format=%s -2 >actual &&
 114        test_cmp expected actual
 115'
 116
 117test_done