mailmap: plug memory leak in read_mailmap_blob()
[git/gitster.git] / t / t2405-worktree-submodule.sh
blob1d7f60563387f9c2f53dfc3a79ac0289afe57611
1 #!/bin/sh
3 test_description='Combination of submodules and multiple worktrees'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 base_path=$(pwd -P)
13 test_expect_success 'setup: create origin repos' '
14 git config --global protocol.file.allow always &&
15 git init origin/sub &&
16 test_commit -C origin/sub file1 &&
17 git init origin/main &&
18 test_commit -C origin/main first &&
19 git -C origin/main submodule add ../sub &&
20 git -C origin/main commit -m "add sub" &&
21 test_commit -C origin/sub "file1 updated" file1 file1updated file1updated &&
22 git -C origin/main/sub pull &&
23 git -C origin/main add sub &&
24 git -C origin/main commit -m "sub updated"
27 test_expect_success 'setup: clone superproject to create main worktree' '
28 git clone --recursive "$base_path/origin/main" main
31 rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
32 rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
34 test_expect_success 'add superproject worktree' '
35 git -C main worktree add "$base_path/worktree" "$rev1_hash_main"
38 test_expect_failure 'submodule is checked out just after worktree add' '
39 git -C worktree diff --submodule main"^!" >out &&
40 grep "file1 updated" out
43 test_expect_success 'add superproject worktree and initialize submodules' '
44 git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" &&
45 git -C worktree-submodule-update submodule update
48 test_expect_success 'submodule is checked out just after submodule update in linked worktree' '
49 git -C worktree-submodule-update diff --submodule main"^!" >out &&
50 grep "file1 updated" out
53 test_expect_success 'add superproject worktree and manually add submodule worktree' '
54 git -C main worktree add "$base_path/linked_submodule" "$rev1_hash_main" &&
55 git -C main/sub worktree add "$base_path/linked_submodule/sub" "$rev1_hash_sub"
58 test_expect_success 'submodule is checked out after manually adding submodule worktree' '
59 git -C linked_submodule diff --submodule main"^!" >out &&
60 grep "file1 updated" out
63 test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' '
64 git -C main worktree add "$base_path/checkout-recurse" --detach &&
65 git -C checkout-recurse submodule update --init &&
66 echo "gitdir: ../../main/.git/worktrees/checkout-recurse/modules/sub" >expect-gitfile &&
67 cat checkout-recurse/sub/.git >actual-gitfile &&
68 test_cmp expect-gitfile actual-gitfile &&
69 git -C main/sub rev-parse HEAD >expect-head-main &&
70 git -C checkout-recurse checkout --recurse-submodules HEAD~1 &&
71 cat checkout-recurse/sub/.git >actual-gitfile &&
72 git -C main/sub rev-parse HEAD >actual-head-main &&
73 test_cmp expect-gitfile actual-gitfile &&
74 test_cmp expect-head-main actual-head-main
77 test_expect_success 'core.worktree is removed in $GIT_DIR/modules/<name>/config, not in $GIT_COMMON_DIR/modules/<name>/config' '
78 echo "../../../sub" >expect-main &&
79 git -C main/sub config --get core.worktree >actual-main &&
80 test_cmp expect-main actual-main &&
81 echo "../../../../../../checkout-recurse/sub" >expect-linked &&
82 git -C checkout-recurse/sub config --get core.worktree >actual-linked &&
83 test_cmp expect-linked actual-linked &&
84 git -C checkout-recurse checkout --recurse-submodules first &&
85 test_expect_code 1 git -C main/.git/worktrees/checkout-recurse/modules/sub config --get core.worktree >linked-config &&
86 test_must_be_empty linked-config &&
87 git -C main/sub config --get core.worktree >actual-main &&
88 test_cmp expect-main actual-main
91 test_expect_success 'unsetting core.worktree does not prevent running commands directly against the submodule repository' '
92 git -C main/.git/worktrees/checkout-recurse/modules/sub log
95 test_done