2014-11-30 16:24:47 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_description='test git worktree add'
|
2014-11-30 16:24:47 +08:00
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2016-04-22 21:01:33 +08:00
|
|
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
|
|
|
|
2014-11-30 16:24:47 +08:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit init
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" an existing worktree' '
|
2014-11-30 16:24:58 +08:00
|
|
|
mkdir -p existing/subtree &&
|
2015-07-07 01:30:54 +08:00
|
|
|
test_must_fail git worktree add --detach existing master
|
2014-11-30 16:24:47 +08:00
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" an existing empty worktree' '
|
2014-11-30 16:24:58 +08:00
|
|
|
mkdir existing_empty &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add --detach existing_empty master
|
2014-11-30 16:24:58 +08:00
|
|
|
'
|
|
|
|
|
2016-05-27 21:17:08 +08:00
|
|
|
test_expect_success '"add" using shorthand - fails when no previous branch' '
|
|
|
|
test_must_fail git worktree add existing_short -
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '"add" using - shorthand' '
|
|
|
|
git checkout -b newbranch &&
|
|
|
|
echo hello >myworld &&
|
|
|
|
git add myworld &&
|
|
|
|
git commit -m myworld &&
|
|
|
|
git checkout master &&
|
|
|
|
git worktree add short-hand - &&
|
|
|
|
echo refs/heads/newbranch >expect &&
|
|
|
|
git -C short-hand rev-parse --symbolic-full-name HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" refuses to checkout locked branch' '
|
|
|
|
test_must_fail git worktree add zere master &&
|
2014-11-30 16:24:50 +08:00
|
|
|
! test -d zere &&
|
|
|
|
! test -d .git/worktrees/zere
|
|
|
|
'
|
|
|
|
|
2015-06-12 18:49:24 +08: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-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" worktree' '
|
2014-11-30 16:24:49 +08:00
|
|
|
git rev-parse HEAD >expect &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add --detach here master &&
|
2014-11-30 16:24:47 +08:00
|
|
|
(
|
|
|
|
cd here &&
|
|
|
|
test_cmp ../init.t init.t &&
|
2014-11-30 16:24:49 +08:00
|
|
|
test_must_fail git symbolic-ref HEAD &&
|
|
|
|
git rev-parse HEAD >actual &&
|
|
|
|
test_cmp ../expect actual &&
|
2014-11-30 16:24:47 +08:00
|
|
|
git fsck
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" worktree from a subdir' '
|
2014-11-30 16:24:47 +08:00
|
|
|
(
|
|
|
|
mkdir sub &&
|
|
|
|
cd sub &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add --detach here master &&
|
2014-11-30 16:24:47 +08:00
|
|
|
cd here &&
|
|
|
|
test_cmp ../../init.t init.t
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" from a linked checkout' '
|
2014-11-30 16:24:47 +08:00
|
|
|
(
|
|
|
|
cd here &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add --detach nested-here master &&
|
2014-11-30 16:24:47 +08:00
|
|
|
cd nested-here &&
|
|
|
|
git fsck
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" worktree creating new branch' '
|
|
|
|
git worktree add -b newmaster there master &&
|
2014-11-30 16:24:47 +08: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 16:24:49 +08:00
|
|
|
test_expect_success 'die the same branch is already checked out' '
|
|
|
|
(
|
|
|
|
cd here &&
|
|
|
|
test_must_fail git checkout newmaster
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-18 07:00:03 +08:00
|
|
|
test_expect_success SYMLINKS 'die the same branch is already checked out (symlink)' '
|
|
|
|
head=$(git -C there rev-parse --git-path HEAD) &&
|
|
|
|
ref=$(git -C there symbolic-ref HEAD) &&
|
|
|
|
rm "$head" &&
|
|
|
|
ln -s "$ref" "$head" &&
|
|
|
|
test_must_fail git -C here checkout newmaster
|
|
|
|
'
|
|
|
|
|
2015-01-03 17:41:26 +08:00
|
|
|
test_expect_success 'not die the same branch is already checked out' '
|
|
|
|
(
|
|
|
|
cd here &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add --force anothernewmaster newmaster
|
2015-01-03 17:41:26 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2014-11-30 16:24:49 +08:00
|
|
|
test_expect_success 'not die on re-checking out current branch' '
|
|
|
|
(
|
|
|
|
cd there &&
|
|
|
|
git checkout newmaster
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" from a bare repo' '
|
2014-11-30 16:24:56 +08:00
|
|
|
(
|
|
|
|
git clone --bare . bare &&
|
|
|
|
cd bare &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add -b bare-master ../there2 master
|
2014-11-30 16:24:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success 'checkout from a bare repo without "add"' '
|
2014-11-30 16:24:56 +08:00
|
|
|
(
|
|
|
|
cd bare &&
|
|
|
|
test_must_fail git checkout master
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-10-13 00:41:07 +08:00
|
|
|
test_expect_success '"add" default branch of a bare repo' '
|
|
|
|
(
|
|
|
|
git clone --bare . bare2 &&
|
|
|
|
cd bare2 &&
|
|
|
|
git worktree add ../there3 master
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2014-11-30 16:24:57 +08:00
|
|
|
test_expect_success 'checkout with grafts' '
|
|
|
|
test_when_finished rm .git/info/grafts &&
|
|
|
|
test_commit abc &&
|
2015-12-22 23:05:52 +08:00
|
|
|
SHA1=$(git rev-parse HEAD) &&
|
2014-11-30 16:24:57 +08:00
|
|
|
test_commit def &&
|
|
|
|
test_commit xyz &&
|
2015-12-22 23:05:52 +08:00
|
|
|
echo "$(git rev-parse HEAD) $SHA1" >.git/info/grafts &&
|
2014-11-30 16:24:57 +08:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
xyz
|
|
|
|
abc
|
|
|
|
EOF
|
|
|
|
git log --format=%s -2 >actual &&
|
|
|
|
test_cmp expected actual &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add --detach grafted master &&
|
2014-11-30 16:24:57 +08:00
|
|
|
git --git-dir=grafted/.git log --format=%s -2 >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:54 +08:00
|
|
|
test_expect_success '"add" from relative HEAD' '
|
2015-07-07 01:30:45 +08:00
|
|
|
test_commit a &&
|
|
|
|
test_commit b &&
|
|
|
|
test_commit c &&
|
|
|
|
git rev-parse HEAD~1 >expected &&
|
2015-07-07 01:30:54 +08:00
|
|
|
git worktree add relhead HEAD~1 &&
|
2015-07-07 01:30:45 +08:00
|
|
|
git -C relhead rev-parse HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:58 +08:00
|
|
|
test_expect_success '"add -b" with <branch> omitted' '
|
|
|
|
git worktree add -b burble flornk &&
|
|
|
|
test_cmp_rev HEAD burble
|
|
|
|
'
|
|
|
|
|
2015-07-18 07:00:09 +08:00
|
|
|
test_expect_success '"add --detach" with <branch> omitted' '
|
|
|
|
git worktree add --detach fishhook &&
|
|
|
|
git rev-parse HEAD >expected &&
|
|
|
|
git -C fishhook rev-parse HEAD >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
test_must_fail git -C fishhook symbolic-ref HEAD
|
|
|
|
'
|
|
|
|
|
2015-07-07 01:30:59 +08:00
|
|
|
test_expect_success '"add" with <branch> omitted' '
|
|
|
|
git worktree add wiffle/bat &&
|
|
|
|
test_cmp_rev HEAD bat
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '"add" auto-vivify does not clobber existing branch' '
|
|
|
|
test_commit c1 &&
|
|
|
|
test_commit c2 &&
|
|
|
|
git branch precious HEAD~1 &&
|
|
|
|
test_must_fail git worktree add precious &&
|
|
|
|
test_cmp_rev HEAD~1 precious &&
|
|
|
|
test_path_is_missing precious
|
|
|
|
'
|
|
|
|
|
2015-07-18 07:00:09 +08:00
|
|
|
test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
|
|
|
|
git worktree add --detach mish/mash &&
|
|
|
|
test_must_fail git rev-parse mash -- &&
|
|
|
|
test_must_fail git -C mish/mash symbolic-ref HEAD
|
|
|
|
'
|
|
|
|
|
2015-07-18 07:00:08 +08:00
|
|
|
test_expect_success '"add" -b/-B mutually exclusive' '
|
|
|
|
test_must_fail git worktree add -b poodle -B poodle bamboo master
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '"add" -b/--detach mutually exclusive' '
|
|
|
|
test_must_fail git worktree add -b poodle --detach bamboo master
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '"add" -B/--detach mutually exclusive' '
|
|
|
|
test_must_fail git worktree add -B poodle --detach bamboo master
|
|
|
|
'
|
|
|
|
|
2016-02-15 21:35:33 +08:00
|
|
|
test_expect_success '"add -B" fails if the branch is checked out' '
|
|
|
|
git rev-parse newmaster >before &&
|
|
|
|
test_must_fail git worktree add -B newmaster bamboo master &&
|
|
|
|
git rev-parse newmaster >after &&
|
|
|
|
test_cmp before after
|
|
|
|
'
|
|
|
|
|
2016-02-15 21:35:32 +08:00
|
|
|
test_expect_success 'add -B' '
|
|
|
|
git worktree add -B poodle bamboo2 master^ &&
|
|
|
|
git -C bamboo2 symbolic-ref HEAD >actual &&
|
|
|
|
echo refs/heads/poodle >expected &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
test_cmp_rev master^ poodle
|
|
|
|
'
|
|
|
|
|
2015-09-28 21:06:15 +08:00
|
|
|
test_expect_success 'local clone from linked checkout' '
|
|
|
|
git clone --local here here-clone &&
|
|
|
|
( cd here-clone && git fsck )
|
|
|
|
'
|
|
|
|
|
2016-03-29 18:11:01 +08:00
|
|
|
test_expect_success '"add" worktree with --no-checkout' '
|
|
|
|
git worktree add --no-checkout -b swamp swamp &&
|
|
|
|
! test -e swamp/init.t &&
|
|
|
|
git -C swamp reset --hard &&
|
|
|
|
test_cmp init.t swamp/init.t
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '"add" worktree with --checkout' '
|
|
|
|
git worktree add --checkout -b swmap2 swamp2 &&
|
|
|
|
test_cmp init.t swamp2/init.t
|
|
|
|
'
|
|
|
|
|
2016-04-22 21:01:33 +08:00
|
|
|
test_expect_success 'put a worktree under rebase' '
|
|
|
|
git worktree add under-rebase &&
|
|
|
|
(
|
|
|
|
cd under-rebase &&
|
|
|
|
set_fake_editor &&
|
|
|
|
FAKE_LINES="edit 1" git rebase -i HEAD^ &&
|
|
|
|
git worktree list | grep "under-rebase.*detached HEAD"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add a worktree, checking out a rebased branch' '
|
|
|
|
test_must_fail git worktree add new-rebase under-rebase &&
|
|
|
|
! test -d new-rebase
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checking out a rebased branch from another worktree' '
|
|
|
|
git worktree add new-place &&
|
|
|
|
test_must_fail git -C new-place checkout under-rebase
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'not allow to delete a branch under rebase' '
|
|
|
|
(
|
|
|
|
cd under-rebase &&
|
|
|
|
test_must_fail git branch -D under-rebase
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-04-22 21:01:36 +08:00
|
|
|
test_expect_success 'rename a branch under rebase not allowed' '
|
|
|
|
test_must_fail git branch -M under-rebase rebase-with-new-name
|
|
|
|
'
|
|
|
|
|
2016-04-22 21:01:33 +08:00
|
|
|
test_expect_success 'check out from current worktree branch ok' '
|
|
|
|
(
|
|
|
|
cd under-rebase &&
|
|
|
|
git checkout under-rebase &&
|
|
|
|
git checkout - &&
|
|
|
|
git rebase --abort
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-04-22 21:01:35 +08:00
|
|
|
test_expect_success 'checkout a branch under bisect' '
|
|
|
|
git worktree add under-bisect &&
|
|
|
|
(
|
|
|
|
cd under-bisect &&
|
|
|
|
git bisect start &&
|
|
|
|
git bisect bad &&
|
|
|
|
git bisect good HEAD~2 &&
|
|
|
|
git worktree list | grep "under-bisect.*detached HEAD" &&
|
|
|
|
test_must_fail git worktree add new-bisect under-bisect &&
|
|
|
|
! test -d new-bisect
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-04-22 21:01:36 +08:00
|
|
|
test_expect_success 'rename a branch under bisect not allowed' '
|
|
|
|
test_must_fail git branch -M under-bisect bisect-with-new-name
|
|
|
|
'
|
|
|
|
|
2014-11-30 16:24:47 +08:00
|
|
|
test_done
|