Skip to content

Commit f194b1e

Browse files
sunshinecogitster
authored andcommitted
tests: worktree: retrofit "checkout --to" tests for "worktree add"
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbdf60f commit f194b1e

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

t/t2025-checkout-to.sh renamed to t/t2025-worktree-add.sh

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
#!/bin/sh
22

3-
test_description='test git checkout --to'
3+
test_description='test git worktree add'
44

55
. ./test-lib.sh
66

77
test_expect_success 'setup' '
88
test_commit init
99
'
1010

11-
test_expect_success 'checkout --to not updating paths' '
12-
test_must_fail git checkout --to -- init.t
13-
'
14-
15-
test_expect_success 'checkout --to an existing worktree' '
11+
test_expect_success '"add" an existing worktree' '
1612
mkdir -p existing/subtree &&
17-
test_must_fail git checkout --detach --to existing master
13+
test_must_fail git worktree add --detach existing master
1814
'
1915

20-
test_expect_success 'checkout --to an existing empty worktree' '
16+
test_expect_success '"add" an existing empty worktree' '
2117
mkdir existing_empty &&
22-
git checkout --detach --to existing_empty master
18+
git worktree add --detach existing_empty master
2319
'
2420

25-
test_expect_success 'checkout --to refuses to checkout locked branch' '
26-
test_must_fail git checkout --to zere master &&
21+
test_expect_success '"add" refuses to checkout locked branch' '
22+
test_must_fail git worktree add zere master &&
2723
! test -d zere &&
2824
! test -d .git/worktrees/zere
2925
'
@@ -36,9 +32,9 @@ test_expect_success 'checking out paths not complaining about linked checkouts'
3632
)
3733
'
3834

39-
test_expect_success 'checkout --to a new worktree' '
35+
test_expect_success '"add" worktree' '
4036
git rev-parse HEAD >expect &&
41-
git checkout --detach --to here master &&
37+
git worktree add --detach here master &&
4238
(
4339
cd here &&
4440
test_cmp ../init.t init.t &&
@@ -49,27 +45,27 @@ test_expect_success 'checkout --to a new worktree' '
4945
)
5046
'
5147

52-
test_expect_success 'checkout --to a new worktree from a subdir' '
48+
test_expect_success '"add" worktree from a subdir' '
5349
(
5450
mkdir sub &&
5551
cd sub &&
56-
git checkout --detach --to here master &&
52+
git worktree add --detach here master &&
5753
cd here &&
5854
test_cmp ../../init.t init.t
5955
)
6056
'
6157

62-
test_expect_success 'checkout --to from a linked checkout' '
58+
test_expect_success '"add" from a linked checkout' '
6359
(
6460
cd here &&
65-
git checkout --detach --to nested-here master &&
61+
git worktree add --detach nested-here master &&
6662
cd nested-here &&
6763
git fsck
6864
)
6965
'
7066

71-
test_expect_success 'checkout --to a new worktree creating new branch' '
72-
git checkout --to there -b newmaster master &&
67+
test_expect_success '"add" worktree creating new branch' '
68+
git worktree add -b newmaster there master &&
7369
(
7470
cd there &&
7571
test_cmp ../init.t init.t &&
@@ -90,7 +86,7 @@ test_expect_success 'die the same branch is already checked out' '
9086
test_expect_success 'not die the same branch is already checked out' '
9187
(
9288
cd here &&
93-
git checkout --ignore-other-worktrees --to anothernewmaster newmaster
89+
git worktree add --force anothernewmaster newmaster
9490
)
9591
'
9692

@@ -101,15 +97,15 @@ test_expect_success 'not die on re-checking out current branch' '
10197
)
10298
'
10399

104-
test_expect_success 'checkout --to from a bare repo' '
100+
test_expect_success '"add" from a bare repo' '
105101
(
106102
git clone --bare . bare &&
107103
cd bare &&
108-
git checkout --to ../there2 -b bare-master master
104+
git worktree add -b bare-master ../there2 master
109105
)
110106
'
111107

112-
test_expect_success 'checkout from a bare repo without --to' '
108+
test_expect_success 'checkout from a bare repo without "add"' '
113109
(
114110
cd bare &&
115111
test_must_fail git checkout master
@@ -129,17 +125,17 @@ test_expect_success 'checkout with grafts' '
129125
EOF
130126
git log --format=%s -2 >actual &&
131127
test_cmp expected actual &&
132-
git checkout --detach --to grafted master &&
128+
git worktree add --detach grafted master &&
133129
git --git-dir=grafted/.git log --format=%s -2 >actual &&
134130
test_cmp expected actual
135131
'
136132

137-
test_expect_success 'checkout --to from relative HEAD' '
133+
test_expect_success '"add" from relative HEAD' '
138134
test_commit a &&
139135
test_commit b &&
140136
test_commit c &&
141137
git rev-parse HEAD~1 >expected &&
142-
git checkout --to relhead HEAD~1 &&
138+
git worktree add relhead HEAD~1 &&
143139
git -C relhead rev-parse HEAD >actual &&
144140
test_cmp expected actual
145141
'

t/t2026-prune-linked-checkouts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test_expect_success 'not prune recent checkouts' '
8888

8989
test_expect_success 'not prune proper checkouts' '
9090
test_when_finished rm -r .git/worktrees &&
91-
git checkout "--to=$PWD/nop" --detach master &&
91+
git worktree add --detach "$PWD/nop" master &&
9292
git worktree prune &&
9393
test -d .git/worktrees/nop
9494
'

t/t7410-submodule-checkout-to.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1
3333
test_expect_success 'checkout main' \
3434
'mkdir default_checkout &&
3535
(cd clone/main &&
36-
git checkout --to "$base_path/default_checkout/main" "$rev1_hash_main")'
36+
git worktree add "$base_path/default_checkout/main" "$rev1_hash_main")'
3737

3838
test_expect_failure 'can see submodule diffs just after checkout' \
3939
'(cd default_checkout/main && git diff --submodule master"^!" | grep "file1 updated")'
4040

4141
test_expect_success 'checkout main and initialize independed clones' \
4242
'mkdir fully_cloned_submodule &&
4343
(cd clone/main &&
44-
git checkout --to "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
44+
git worktree add "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
4545
(cd fully_cloned_submodule/main && git submodule update)'
4646

4747
test_expect_success 'can see submodule diffs after independed cloning' \

0 commit comments

Comments
 (0)