2014-11-30 08:24:47 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_description='test git worktree add'
|
2014-11-30 08:24:47 +00:00
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit init
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" an existing worktree' '
|
2014-11-30 08:24:58 +00:00
|
|
|
mkdir -p existing/subtree &&
|
2015-07-06 17:30:54 +00:00
|
|
|
test_must_fail git worktree add --detach existing master
|
2014-11-30 08:24:47 +00:00
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" an existing empty worktree' '
|
2014-11-30 08:24:58 +00:00
|
|
|
mkdir existing_empty &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add --detach existing_empty master
|
2014-11-30 08:24:58 +00:00
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" refuses to checkout locked branch' '
|
|
|
|
test_must_fail git worktree add zere master &&
|
2014-11-30 08:24:50 +00:00
|
|
|
! test -d zere &&
|
|
|
|
! test -d .git/worktrees/zere
|
|
|
|
'
|
|
|
|
|
2015-06-12 10:49:24 +00:00
|
|
|
test_expect_success 'checking out paths not complaining about linked checkouts' '
|
|
|
|
(
|
|
|
|
cd existing_empty &&
|
|
|
|
echo dirty >>init.t &&
|
|
|
|
git checkout master -- init.t
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" worktree' '
|
2014-11-30 08:24:49 +00:00
|
|
|
git rev-parse HEAD >expect &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add --detach here master &&
|
2014-11-30 08:24:47 +00:00
|
|
|
(
|
|
|
|
cd here &&
|
|
|
|
test_cmp ../init.t init.t &&
|
2014-11-30 08:24:49 +00:00
|
|
|
test_must_fail git symbolic-ref HEAD &&
|
|
|
|
git rev-parse HEAD >actual &&
|
|
|
|
test_cmp ../expect actual &&
|
2014-11-30 08:24:47 +00:00
|
|
|
git fsck
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" worktree from a subdir' '
|
2014-11-30 08:24:47 +00:00
|
|
|
(
|
|
|
|
mkdir sub &&
|
|
|
|
cd sub &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add --detach here master &&
|
2014-11-30 08:24:47 +00:00
|
|
|
cd here &&
|
|
|
|
test_cmp ../../init.t init.t
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" from a linked checkout' '
|
2014-11-30 08:24:47 +00:00
|
|
|
(
|
|
|
|
cd here &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add --detach nested-here master &&
|
2014-11-30 08:24:47 +00:00
|
|
|
cd nested-here &&
|
|
|
|
git fsck
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" worktree creating new branch' '
|
|
|
|
git worktree add -b newmaster there master &&
|
2014-11-30 08:24:47 +00:00
|
|
|
(
|
|
|
|
cd there &&
|
|
|
|
test_cmp ../init.t init.t &&
|
|
|
|
git symbolic-ref HEAD >actual &&
|
|
|
|
echo refs/heads/newmaster >expect &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git fsck
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2014-11-30 08:24:49 +00:00
|
|
|
test_expect_success 'die the same branch is already checked out' '
|
|
|
|
(
|
|
|
|
cd here &&
|
|
|
|
test_must_fail git checkout newmaster
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-01-03 09:41:26 +00:00
|
|
|
test_expect_success 'not die the same branch is already checked out' '
|
|
|
|
(
|
|
|
|
cd here &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add --force anothernewmaster newmaster
|
2015-01-03 09:41:26 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2014-11-30 08:24:49 +00:00
|
|
|
test_expect_success 'not die on re-checking out current branch' '
|
|
|
|
(
|
|
|
|
cd there &&
|
|
|
|
git checkout newmaster
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" from a bare repo' '
|
2014-11-30 08:24:56 +00:00
|
|
|
(
|
|
|
|
git clone --bare . bare &&
|
|
|
|
cd bare &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add -b bare-master ../there2 master
|
2014-11-30 08:24:56 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success 'checkout from a bare repo without "add"' '
|
2014-11-30 08:24:56 +00:00
|
|
|
(
|
|
|
|
cd bare &&
|
|
|
|
test_must_fail git checkout master
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2014-11-30 08:24:57 +00:00
|
|
|
test_expect_success 'checkout with grafts' '
|
|
|
|
test_when_finished rm .git/info/grafts &&
|
|
|
|
test_commit abc &&
|
|
|
|
SHA1=`git rev-parse HEAD` &&
|
|
|
|
test_commit def &&
|
|
|
|
test_commit xyz &&
|
|
|
|
echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
xyz
|
|
|
|
abc
|
|
|
|
EOF
|
|
|
|
git log --format=%s -2 >actual &&
|
|
|
|
test_cmp expected actual &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add --detach grafted master &&
|
2014-11-30 08:24:57 +00:00
|
|
|
git --git-dir=grafted/.git log --format=%s -2 >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-07-06 17:30:54 +00:00
|
|
|
test_expect_success '"add" from relative HEAD' '
|
2015-07-06 17:30:45 +00:00
|
|
|
test_commit a &&
|
|
|
|
test_commit b &&
|
|
|
|
test_commit c &&
|
|
|
|
git rev-parse HEAD~1 >expected &&
|
2015-07-06 17:30:54 +00:00
|
|
|
git worktree add relhead HEAD~1 &&
|
2015-07-06 17:30:45 +00:00
|
|
|
git -C relhead rev-parse HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-11-30 08:24:47 +00:00
|
|
|
test_done
|