]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2405-worktree-submodule.sh
strmap: enable allocations to come from a mem_pool
[thirdparty/git.git] / t / t2405-worktree-submodule.sh
CommitLineData
df56607d
MK
1#!/bin/sh
2
773c60a4 3test_description='Combination of submodules and multiple worktrees'
df56607d
MK
4
5. ./test-lib.sh
6
7base_path=$(pwd -P)
8
4eaadc84
PB
9test_expect_success 'setup: create origin repos' '
10 git init origin/sub &&
11 test_commit -C origin/sub file1 &&
12 git init origin/main &&
a9472afb 13 test_commit -C origin/main first &&
4eaadc84
PB
14 git -C origin/main submodule add ../sub &&
15 git -C origin/main commit -m "add sub" &&
16 test_commit -C origin/sub "file1 updated" file1 file1updated file1updated &&
31158c7e 17 git -C origin/main/sub pull &&
4eaadc84
PB
18 git -C origin/main add sub &&
19 git -C origin/main commit -m "sub updated"
31158c7e
SB
20'
21
129510a0
PB
22test_expect_success 'setup: clone superproject to create main worktree' '
23 git clone --recursive "$base_path/origin/main" main
31158c7e 24'
df56607d
MK
25
26rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
27rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
28
129510a0
PB
29test_expect_success 'add superproject worktree' '
30 git -C main worktree add "$base_path/worktree" "$rev1_hash_main"
31158c7e 31'
df56607d 32
129510a0
PB
33test_expect_failure 'submodule is checked out just after worktree add' '
34 git -C worktree diff --submodule master"^!" >out &&
31158c7e
SB
35 grep "file1 updated" out
36'
df56607d 37
129510a0
PB
38test_expect_success 'add superproject worktree and initialize submodules' '
39 git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" &&
40 git -C worktree-submodule-update submodule update
31158c7e 41'
df56607d 42
129510a0
PB
43test_expect_success 'submodule is checked out just after submodule update in linked worktree' '
44 git -C worktree-submodule-update diff --submodule master"^!" >out &&
31158c7e
SB
45 grep "file1 updated" out
46'
df56607d 47
129510a0
PB
48test_expect_success 'add superproject worktree and manually add submodule worktree' '
49 git -C main worktree add "$base_path/linked_submodule" "$rev1_hash_main" &&
50 git -C main/sub worktree add "$base_path/linked_submodule/sub" "$rev1_hash_sub"
31158c7e 51'
11f9dd71 52
129510a0
PB
53test_expect_success 'submodule is checked out after manually adding submodule worktree' '
54 git -C linked_submodule diff --submodule master"^!" >out &&
31158c7e
SB
55 grep "file1 updated" out
56'
11f9dd71 57
a9472afb
PB
58test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' '
59 git -C main worktree add "$base_path/checkout-recurse" --detach &&
60 git -C checkout-recurse submodule update --init &&
61 echo "gitdir: ../../main/.git/worktrees/checkout-recurse/modules/sub" >expect-gitfile &&
62 cat checkout-recurse/sub/.git >actual-gitfile &&
63 test_cmp expect-gitfile actual-gitfile &&
64 git -C main/sub rev-parse HEAD >expect-head-main &&
65 git -C checkout-recurse checkout --recurse-submodules HEAD~1 &&
66 cat checkout-recurse/sub/.git >actual-gitfile &&
67 git -C main/sub rev-parse HEAD >actual-head-main &&
68 test_cmp expect-gitfile actual-gitfile &&
69 test_cmp expect-head-main actual-head-main
70'
71
72test_expect_success 'core.worktree is removed in $GIT_DIR/modules/<name>/config, not in $GIT_COMMON_DIR/modules/<name>/config' '
73 echo "../../../sub" >expect-main &&
74 git -C main/sub config --get core.worktree >actual-main &&
75 test_cmp expect-main actual-main &&
76 echo "../../../../../../checkout-recurse/sub" >expect-linked &&
77 git -C checkout-recurse/sub config --get core.worktree >actual-linked &&
78 test_cmp expect-linked actual-linked &&
79 git -C checkout-recurse checkout --recurse-submodules first &&
80 test_expect_code 1 git -C main/.git/worktrees/checkout-recurse/modules/sub config --get core.worktree >linked-config &&
81 test_must_be_empty linked-config &&
82 git -C main/sub config --get core.worktree >actual-main &&
83 test_cmp expect-main actual-main
84'
85
86test_expect_success 'unsetting core.worktree does not prevent running commands directly against the submodule repository' '
87 git -C main/.git/worktrees/checkout-recurse/modules/sub log
88'
89
df56607d 90test_done