config.c: remove current_parsing_scope
[git.git] / t / t2405-worktree-submodule.sh
blob11018f37c70c02e9052b36be9edb8b05211bcf8d
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-lib.sh
10 base_path=$(pwd -P)
12 test_expect_success 'setup: create origin repos' '
13 git config --global protocol.file.allow always &&
14 git init origin/sub &&
15 test_commit -C origin/sub file1 &&
16 git init origin/main &&
17 test_commit -C origin/main first &&
18 git -C origin/main submodule add ../sub &&
19 git -C origin/main commit -m "add sub" &&
20 test_commit -C origin/sub "file1 updated" file1 file1updated file1updated &&
21 git -C origin/main/sub pull &&
22 git -C origin/main add sub &&
23 git -C origin/main commit -m "sub updated"
26 test_expect_success 'setup: clone superproject to create main worktree' '
27 git clone --recursive "$base_path/origin/main" main
30 rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
31 rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
33 test_expect_success 'add superproject worktree' '
34 git -C main worktree add "$base_path/worktree" "$rev1_hash_main"
37 test_expect_failure 'submodule is checked out just after worktree add' '
38 git -C worktree diff --submodule main"^!" >out &&
39 grep "file1 updated" out
42 test_expect_success 'add superproject worktree and initialize submodules' '
43 git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" &&
44 git -C worktree-submodule-update submodule update
47 test_expect_success 'submodule is checked out just after submodule update in linked worktree' '
48 git -C worktree-submodule-update diff --submodule main"^!" >out &&
49 grep "file1 updated" out
52 test_expect_success 'add superproject worktree and manually add submodule worktree' '
53 git -C main worktree add "$base_path/linked_submodule" "$rev1_hash_main" &&
54 git -C main/sub worktree add "$base_path/linked_submodule/sub" "$rev1_hash_sub"
57 test_expect_success 'submodule is checked out after manually adding submodule worktree' '
58 git -C linked_submodule diff --submodule main"^!" >out &&
59 grep "file1 updated" out
62 test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' '
63 git -C main worktree add "$base_path/checkout-recurse" --detach &&
64 git -C checkout-recurse submodule update --init &&
65 echo "gitdir: ../../main/.git/worktrees/checkout-recurse/modules/sub" >expect-gitfile &&
66 cat checkout-recurse/sub/.git >actual-gitfile &&
67 test_cmp expect-gitfile actual-gitfile &&
68 git -C main/sub rev-parse HEAD >expect-head-main &&
69 git -C checkout-recurse checkout --recurse-submodules HEAD~1 &&
70 cat checkout-recurse/sub/.git >actual-gitfile &&
71 git -C main/sub rev-parse HEAD >actual-head-main &&
72 test_cmp expect-gitfile actual-gitfile &&
73 test_cmp expect-head-main actual-head-main
76 test_expect_success 'core.worktree is removed in $GIT_DIR/modules/<name>/config, not in $GIT_COMMON_DIR/modules/<name>/config' '
77 echo "../../../sub" >expect-main &&
78 git -C main/sub config --get core.worktree >actual-main &&
79 test_cmp expect-main actual-main &&
80 echo "../../../../../../checkout-recurse/sub" >expect-linked &&
81 git -C checkout-recurse/sub config --get core.worktree >actual-linked &&
82 test_cmp expect-linked actual-linked &&
83 git -C checkout-recurse checkout --recurse-submodules first &&
84 test_expect_code 1 git -C main/.git/worktrees/checkout-recurse/modules/sub config --get core.worktree >linked-config &&
85 test_must_be_empty linked-config &&
86 git -C main/sub config --get core.worktree >actual-main &&
87 test_cmp expect-main actual-main
90 test_expect_success 'unsetting core.worktree does not prevent running commands directly against the submodule repository' '
91 git -C main/.git/worktrees/checkout-recurse/modules/sub log
94 test_done