Git fork
1#!/bin/sh
2
3test_description='Test cloning repos with submodules using remote-tracking branches'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
10pwd=$(pwd)
11
12test_expect_success 'setup' '
13 git config --global protocol.file.allow always &&
14 git checkout -b main &&
15 test_commit commit1 &&
16 mkdir sub &&
17 (
18 cd sub &&
19 git init &&
20 test_commit subcommit1 &&
21 git tag sub_when_added_to_super &&
22 git branch other
23 ) &&
24 git submodule add "file://$pwd/sub" sub &&
25 git commit -m "add submodule" &&
26 (
27 cd sub &&
28 test_commit subcommit2
29 )
30'
31
32# bare clone giving "srv.bare" for use as our server.
33test_expect_success 'setup bare clone for server' '
34 git clone --bare "file://$(pwd)/." srv.bare &&
35 git -C srv.bare config --local uploadpack.allowfilter 1 &&
36 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
37'
38
39test_expect_success 'clone with --no-remote-submodules' '
40 test_when_finished "rm -rf super_clone" &&
41 git clone --recurse-submodules --no-remote-submodules "file://$pwd/." super_clone &&
42 (
43 cd super_clone/sub &&
44 git diff --exit-code sub_when_added_to_super
45 )
46'
47
48test_expect_success 'clone with --remote-submodules' '
49 test_when_finished "rm -rf super_clone" &&
50 git clone --recurse-submodules --remote-submodules "file://$pwd/." super_clone &&
51 (
52 cd super_clone/sub &&
53 git diff --exit-code remotes/origin/main
54 )
55'
56
57test_expect_success 'check the default is --no-remote-submodules' '
58 test_when_finished "rm -rf super_clone" &&
59 git clone --recurse-submodules "file://$pwd/." super_clone &&
60 (
61 cd super_clone/sub &&
62 git diff --exit-code sub_when_added_to_super
63 )
64'
65
66test_expect_success 'clone with --single-branch' '
67 test_when_finished "rm -rf super_clone" &&
68 git clone --recurse-submodules --single-branch "file://$pwd/." super_clone &&
69 (
70 cd super_clone/sub &&
71 git rev-parse --verify origin/main &&
72 test_must_fail git rev-parse --verify origin/other
73 )
74'
75
76# do basic partial clone from "srv.bare"
77# confirm partial clone was registered in the local config for super and sub.
78test_expect_success 'clone with --filter' '
79 git clone --recurse-submodules \
80 --filter blob:none --also-filter-submodules \
81 "file://$pwd/srv.bare" super_clone &&
82 test_cmp_config -C super_clone true remote.origin.promisor &&
83 test_cmp_config -C super_clone blob:none remote.origin.partialclonefilter &&
84 test_cmp_config -C super_clone/sub true remote.origin.promisor &&
85 test_cmp_config -C super_clone/sub blob:none remote.origin.partialclonefilter
86'
87
88# check that clone.filterSubmodules works (--also-filter-submodules can be
89# omitted)
90test_expect_success 'filters applied with clone.filterSubmodules' '
91 test_config_global clone.filterSubmodules true &&
92 git clone --recurse-submodules --filter blob:none \
93 "file://$pwd/srv.bare" super_clone2 &&
94 test_cmp_config -C super_clone2 true remote.origin.promisor &&
95 test_cmp_config -C super_clone2 blob:none remote.origin.partialclonefilter &&
96 test_cmp_config -C super_clone2/sub true remote.origin.promisor &&
97 test_cmp_config -C super_clone2/sub blob:none remote.origin.partialclonefilter
98'
99
100test_expect_success '--no-also-filter-submodules overrides clone.filterSubmodules=true' '
101 test_config_global clone.filterSubmodules true &&
102 git clone --recurse-submodules --filter blob:none \
103 --no-also-filter-submodules \
104 "file://$pwd/srv.bare" super_clone3 &&
105 test_cmp_config -C super_clone3 true remote.origin.promisor &&
106 test_cmp_config -C super_clone3 blob:none remote.origin.partialclonefilter &&
107 test_cmp_config -C super_clone3/sub false --default false remote.origin.promisor
108'
109
110test_done