tests: worktree: retrofit "checkout --to" tests for "worktree add"
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 6 Jul 2015 17:30:54 +0000 (13:30 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Jul 2015 18:07:47 +0000 (11:07 -0700)
With the introduction of "git worktree add", "git checkout --to" is
slated for removal. Therefore, retrofit linked worktree creation tests
to use "git worktree add" instead.

(The test to check exclusivity of "checkout --to" and "checkout <paths>"
is dropped altogether since it becomes meaningless with retirement of
"checkout --to".)

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t2025-checkout-to.sh [deleted file]
t/t2025-worktree-add.sh [new file with mode: 0755]
t/t2026-prune-linked-checkouts.sh
t/t7410-submodule-checkout-to.sh
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh
deleted file mode 100755 (executable)
index 0fd731b..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/bin/sh
-
-test_description='test git checkout --to'
-
-. ./test-lib.sh
-
-test_expect_success 'setup' '
-       test_commit init
-'
-
-test_expect_success 'checkout --to not updating paths' '
-       test_must_fail git checkout --to -- init.t
-'
-
-test_expect_success 'checkout --to an existing worktree' '
-       mkdir -p existing/subtree &&
-       test_must_fail git checkout --detach --to existing master
-'
-
-test_expect_success 'checkout --to an existing empty worktree' '
-       mkdir existing_empty &&
-       git checkout --detach --to existing_empty master
-'
-
-test_expect_success 'checkout --to refuses to checkout locked branch' '
-       test_must_fail git checkout --to zere master &&
-       ! test -d zere &&
-       ! test -d .git/worktrees/zere
-'
-
-test_expect_success 'checking out paths not complaining about linked checkouts' '
-       (
-       cd existing_empty &&
-       echo dirty >>init.t &&
-       git checkout master -- init.t
-       )
-'
-
-test_expect_success 'checkout --to a new worktree' '
-       git rev-parse HEAD >expect &&
-       git checkout --detach --to here master &&
-       (
-               cd here &&
-               test_cmp ../init.t init.t &&
-               test_must_fail git symbolic-ref HEAD &&
-               git rev-parse HEAD >actual &&
-               test_cmp ../expect actual &&
-               git fsck
-       )
-'
-
-test_expect_success 'checkout --to a new worktree from a subdir' '
-       (
-               mkdir sub &&
-               cd sub &&
-               git checkout --detach --to here master &&
-               cd here &&
-               test_cmp ../../init.t init.t
-       )
-'
-
-test_expect_success 'checkout --to from a linked checkout' '
-       (
-               cd here &&
-               git checkout --detach --to nested-here master &&
-               cd nested-here &&
-               git fsck
-       )
-'
-
-test_expect_success 'checkout --to a new worktree creating new branch' '
-       git checkout --to there -b newmaster master &&
-       (
-               cd there &&
-               test_cmp ../init.t init.t &&
-               git symbolic-ref HEAD >actual &&
-               echo refs/heads/newmaster >expect &&
-               test_cmp expect actual &&
-               git fsck
-       )
-'
-
-test_expect_success 'die the same branch is already checked out' '
-       (
-               cd here &&
-               test_must_fail git checkout newmaster
-       )
-'
-
-test_expect_success 'not die the same branch is already checked out' '
-       (
-               cd here &&
-               git checkout --ignore-other-worktrees --to anothernewmaster newmaster
-       )
-'
-
-test_expect_success 'not die on re-checking out current branch' '
-       (
-               cd there &&
-               git checkout newmaster
-       )
-'
-
-test_expect_success 'checkout --to from a bare repo' '
-       (
-               git clone --bare . bare &&
-               cd bare &&
-               git checkout --to ../there2 -b bare-master master
-       )
-'
-
-test_expect_success 'checkout from a bare repo without --to' '
-       (
-               cd bare &&
-               test_must_fail git checkout master
-       )
-'
-
-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 &&
-       git checkout --detach --to grafted master &&
-       git --git-dir=grafted/.git log --format=%s -2 >actual &&
-       test_cmp expected actual
-'
-
-test_expect_success 'checkout --to from relative HEAD' '
-       test_commit a &&
-       test_commit b &&
-       test_commit c &&
-       git rev-parse HEAD~1 >expected &&
-       git checkout --to relhead HEAD~1 &&
-       git -C relhead rev-parse HEAD >actual &&
-       test_cmp expected actual
-'
-
-test_done
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
new file mode 100755 (executable)
index 0000000..192c936
--- /dev/null
@@ -0,0 +1,143 @@
+#!/bin/sh
+
+test_description='test git worktree add'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       test_commit init
+'
+
+test_expect_success '"add" an existing worktree' '
+       mkdir -p existing/subtree &&
+       test_must_fail git worktree add --detach existing master
+'
+
+test_expect_success '"add" an existing empty worktree' '
+       mkdir existing_empty &&
+       git worktree add --detach existing_empty master
+'
+
+test_expect_success '"add" refuses to checkout locked branch' '
+       test_must_fail git worktree add zere master &&
+       ! test -d zere &&
+       ! test -d .git/worktrees/zere
+'
+
+test_expect_success 'checking out paths not complaining about linked checkouts' '
+       (
+       cd existing_empty &&
+       echo dirty >>init.t &&
+       git checkout master -- init.t
+       )
+'
+
+test_expect_success '"add" worktree' '
+       git rev-parse HEAD >expect &&
+       git worktree add --detach here master &&
+       (
+               cd here &&
+               test_cmp ../init.t init.t &&
+               test_must_fail git symbolic-ref HEAD &&
+               git rev-parse HEAD >actual &&
+               test_cmp ../expect actual &&
+               git fsck
+       )
+'
+
+test_expect_success '"add" worktree from a subdir' '
+       (
+               mkdir sub &&
+               cd sub &&
+               git worktree add --detach here master &&
+               cd here &&
+               test_cmp ../../init.t init.t
+       )
+'
+
+test_expect_success '"add" from a linked checkout' '
+       (
+               cd here &&
+               git worktree add --detach nested-here master &&
+               cd nested-here &&
+               git fsck
+       )
+'
+
+test_expect_success '"add" worktree creating new branch' '
+       git worktree add -b newmaster there master &&
+       (
+               cd there &&
+               test_cmp ../init.t init.t &&
+               git symbolic-ref HEAD >actual &&
+               echo refs/heads/newmaster >expect &&
+               test_cmp expect actual &&
+               git fsck
+       )
+'
+
+test_expect_success 'die the same branch is already checked out' '
+       (
+               cd here &&
+               test_must_fail git checkout newmaster
+       )
+'
+
+test_expect_success 'not die the same branch is already checked out' '
+       (
+               cd here &&
+               git worktree add --force anothernewmaster newmaster
+       )
+'
+
+test_expect_success 'not die on re-checking out current branch' '
+       (
+               cd there &&
+               git checkout newmaster
+       )
+'
+
+test_expect_success '"add" from a bare repo' '
+       (
+               git clone --bare . bare &&
+               cd bare &&
+               git worktree add -b bare-master ../there2 master
+       )
+'
+
+test_expect_success 'checkout from a bare repo without "add"' '
+       (
+               cd bare &&
+               test_must_fail git checkout master
+       )
+'
+
+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 &&
+       git worktree add --detach grafted master &&
+       git --git-dir=grafted/.git log --format=%s -2 >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success '"add" from relative HEAD' '
+       test_commit a &&
+       test_commit b &&
+       test_commit c &&
+       git rev-parse HEAD~1 >expected &&
+       git worktree add relhead HEAD~1 &&
+       git -C relhead rev-parse HEAD >actual &&
+       test_cmp expected actual
+'
+
+test_done
index e872f02dac37638a64918d1e3f585aacd2f94516..a0f1e3bb800ec6943648eeffb9e7ca84e328fa41 100755 (executable)
@@ -88,7 +88,7 @@ test_expect_success 'not prune recent checkouts' '
 
 test_expect_success 'not prune proper checkouts' '
        test_when_finished rm -r .git/worktrees &&
-       git checkout "--to=$PWD/nop" --detach master &&
+       git worktree add --detach "$PWD/nop" master &&
        git worktree prune &&
        test -d .git/worktrees/nop
 '
index 8f30aed6cc3f1cbf564a592191777b5ab46594a2..3f609e8909c463e7d396915d273d82785b238000 100755 (executable)
@@ -33,7 +33,7 @@ rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1
 test_expect_success 'checkout main' \
     'mkdir default_checkout &&
     (cd clone/main &&
-       git checkout --to "$base_path/default_checkout/main" "$rev1_hash_main")'
+       git worktree add "$base_path/default_checkout/main" "$rev1_hash_main")'
 
 test_expect_failure 'can see submodule diffs just after checkout' \
     '(cd default_checkout/main && git diff --submodule master"^!" | grep "file1 updated")'
@@ -41,7 +41,7 @@ test_expect_failure 'can see submodule diffs just after checkout' \
 test_expect_success 'checkout main and initialize independed clones' \
     'mkdir fully_cloned_submodule &&
     (cd clone/main &&
-       git checkout --to "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
+       git worktree add "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
     (cd fully_cloned_submodule/main && git submodule update)'
 
 test_expect_success 'can see submodule diffs after independed cloning' \