blob: 5a4d7936a72aac48fde876076393956bb83d42e9 [file] [log] [blame]
Ben Avison4c691012019-05-19 15:26:49 +01001#!/bin/sh
2
3test_description='Test cloning repos with submodules using remote-tracking branches'
4
Johannes Schindelin95cf2c02020-11-18 23:44:35 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Ævar Arnfjörð Bjarmasondd4143e2022-11-08 19:17:47 +01008TEST_PASSES_SANITIZE_LEAK=true
Ben Avison4c691012019-05-19 15:26:49 +01009. ./test-lib.sh
10
11pwd=$(pwd)
12
13test_expect_success 'setup' '
Taylor Blau225d2d52022-07-29 15:21:06 -040014 git config --global protocol.file.allow always &&
Johannes Schindelin95cf2c02020-11-18 23:44:35 +000015 git checkout -b main &&
Ben Avison4c691012019-05-19 15:26:49 +010016 test_commit commit1 &&
17 mkdir sub &&
18 (
19 cd sub &&
20 git init &&
21 test_commit subcommit1 &&
Emily Shaffer132f6002020-02-20 19:10:27 -080022 git tag sub_when_added_to_super &&
23 git branch other
Ben Avison4c691012019-05-19 15:26:49 +010024 ) &&
25 git submodule add "file://$pwd/sub" sub &&
26 git commit -m "add submodule" &&
27 (
28 cd sub &&
29 test_commit subcommit2
30 )
31'
32
Josh Steadmonf05da2b2022-02-04 21:00:49 -080033# bare clone giving "srv.bare" for use as our server.
34test_expect_success 'setup bare clone for server' '
35 git clone --bare "file://$(pwd)/." srv.bare &&
36 git -C srv.bare config --local uploadpack.allowfilter 1 &&
37 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
38'
39
Ben Avison4c691012019-05-19 15:26:49 +010040test_expect_success 'clone with --no-remote-submodules' '
41 test_when_finished "rm -rf super_clone" &&
42 git clone --recurse-submodules --no-remote-submodules "file://$pwd/." super_clone &&
43 (
44 cd super_clone/sub &&
45 git diff --exit-code sub_when_added_to_super
46 )
47'
48
49test_expect_success 'clone with --remote-submodules' '
50 test_when_finished "rm -rf super_clone" &&
51 git clone --recurse-submodules --remote-submodules "file://$pwd/." super_clone &&
52 (
53 cd super_clone/sub &&
Johannes Schindelin95cf2c02020-11-18 23:44:35 +000054 git diff --exit-code remotes/origin/main
Ben Avison4c691012019-05-19 15:26:49 +010055 )
56'
57
58test_expect_success 'check the default is --no-remote-submodules' '
59 test_when_finished "rm -rf super_clone" &&
60 git clone --recurse-submodules "file://$pwd/." super_clone &&
61 (
62 cd super_clone/sub &&
63 git diff --exit-code sub_when_added_to_super
64 )
65'
66
Emily Shaffer132f6002020-02-20 19:10:27 -080067test_expect_success 'clone with --single-branch' '
68 test_when_finished "rm -rf super_clone" &&
69 git clone --recurse-submodules --single-branch "file://$pwd/." super_clone &&
70 (
71 cd super_clone/sub &&
Johannes Schindelin95cf2c02020-11-18 23:44:35 +000072 git rev-parse --verify origin/main &&
Emily Shaffer132f6002020-02-20 19:10:27 -080073 test_must_fail git rev-parse --verify origin/other
74 )
75'
76
Josh Steadmonf05da2b2022-02-04 21:00:49 -080077# do basic partial clone from "srv.bare"
78# confirm partial clone was registered in the local config for super and sub.
79test_expect_success 'clone with --filter' '
80 git clone --recurse-submodules \
81 --filter blob:none --also-filter-submodules \
82 "file://$pwd/srv.bare" super_clone &&
83 test_cmp_config -C super_clone true remote.origin.promisor &&
84 test_cmp_config -C super_clone blob:none remote.origin.partialclonefilter &&
85 test_cmp_config -C super_clone/sub true remote.origin.promisor &&
86 test_cmp_config -C super_clone/sub blob:none remote.origin.partialclonefilter
87'
88
89# check that clone.filterSubmodules works (--also-filter-submodules can be
90# omitted)
91test_expect_success 'filters applied with clone.filterSubmodules' '
92 test_config_global clone.filterSubmodules true &&
93 git clone --recurse-submodules --filter blob:none \
94 "file://$pwd/srv.bare" super_clone2 &&
95 test_cmp_config -C super_clone2 true remote.origin.promisor &&
96 test_cmp_config -C super_clone2 blob:none remote.origin.partialclonefilter &&
97 test_cmp_config -C super_clone2/sub true remote.origin.promisor &&
98 test_cmp_config -C super_clone2/sub blob:none remote.origin.partialclonefilter
99'
100
101test_expect_success '--no-also-filter-submodules overrides clone.filterSubmodules=true' '
102 test_config_global clone.filterSubmodules true &&
103 git clone --recurse-submodules --filter blob:none \
104 --no-also-filter-submodules \
105 "file://$pwd/srv.bare" super_clone3 &&
106 test_cmp_config -C super_clone3 true remote.origin.promisor &&
107 test_cmp_config -C super_clone3 blob:none remote.origin.partialclonefilter &&
108 test_cmp_config -C super_clone3/sub false --default false remote.origin.promisor
109'
110
Ben Avison4c691012019-05-19 15:26:49 +0100111test_done