blob: c2a2bb453eeabcc8725bffae2c537ec99b8a7d87 [file] [log] [blame]
Stefan Bellerd22eb042016-04-25 18:12:27 -07001#!/bin/sh
2
3test_description='Test shallow cloning of repos with submodules'
4
Ævar Arnfjörð Bjarmasondd4143e2022-11-08 19:17:47 +01005TEST_PASSES_SANITIZE_LEAK=true
Stefan Bellerd22eb042016-04-25 18:12:27 -07006. ./test-lib.sh
7
8pwd=$(pwd)
9
10test_expect_success 'setup' '
Johannes Schindelin95cf2c02020-11-18 23:44:35 +000011 git checkout -b main &&
Stefan Bellerd22eb042016-04-25 18:12:27 -070012 test_commit commit1 &&
13 test_commit commit2 &&
14 mkdir sub &&
15 (
16 cd sub &&
17 git init &&
18 test_commit subcommit1 &&
19 test_commit subcommit2 &&
20 test_commit subcommit3
21 ) &&
22 git submodule add "file://$pwd/sub" sub &&
23 git commit -m "add submodule"
24'
25
26test_expect_success 'nonshallow clone implies nonshallow submodule' '
27 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040028 test_config_global protocol.file.allow always &&
Stefan Bellerd22eb042016-04-25 18:12:27 -070029 git clone --recurse-submodules "file://$pwd/." super_clone &&
Stefan Beller5819c2e2016-06-20 10:21:18 -070030 git -C super_clone log --oneline >lines &&
31 test_line_count = 3 lines &&
32 git -C super_clone/sub log --oneline >lines &&
33 test_line_count = 3 lines
Stefan Bellerd22eb042016-04-25 18:12:27 -070034'
35
Junio C Hamano18a74a02016-06-19 13:51:56 -070036test_expect_success 'shallow clone with shallow submodule' '
37 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040038 test_config_global protocol.file.allow always &&
Junio C Hamano18a74a02016-06-19 13:51:56 -070039 git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone &&
Stefan Beller5819c2e2016-06-20 10:21:18 -070040 git -C super_clone log --oneline >lines &&
41 test_line_count = 2 lines &&
42 git -C super_clone/sub log --oneline >lines &&
43 test_line_count = 1 lines
Junio C Hamano18a74a02016-06-19 13:51:56 -070044'
45
46test_expect_success 'shallow clone does not imply shallow submodule' '
Stefan Bellerd22eb042016-04-25 18:12:27 -070047 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040048 test_config_global protocol.file.allow always &&
Stefan Bellerd22eb042016-04-25 18:12:27 -070049 git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
Stefan Beller5819c2e2016-06-20 10:21:18 -070050 git -C super_clone log --oneline >lines &&
51 test_line_count = 2 lines &&
52 git -C super_clone/sub log --oneline >lines &&
53 test_line_count = 3 lines
Stefan Bellerd22eb042016-04-25 18:12:27 -070054'
55
56test_expect_success 'shallow clone with non shallow submodule' '
57 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040058 test_config_global protocol.file.allow always &&
Stefan Bellerd22eb042016-04-25 18:12:27 -070059 git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&
Stefan Beller5819c2e2016-06-20 10:21:18 -070060 git -C super_clone log --oneline >lines &&
61 test_line_count = 2 lines &&
62 git -C super_clone/sub log --oneline >lines &&
63 test_line_count = 3 lines
Stefan Bellerd22eb042016-04-25 18:12:27 -070064'
65
66test_expect_success 'non shallow clone with shallow submodule' '
67 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040068 test_config_global protocol.file.allow always &&
Stefan Bellerd22eb042016-04-25 18:12:27 -070069 git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone &&
Stefan Beller5819c2e2016-06-20 10:21:18 -070070 git -C super_clone log --oneline >lines &&
71 test_line_count = 3 lines &&
72 git -C super_clone/sub log --oneline >lines &&
73 test_line_count = 1 lines
Stefan Bellerd22eb042016-04-25 18:12:27 -070074'
75
Stefan Bellerabed0002016-05-26 14:59:43 -070076test_expect_success 'clone follows shallow recommendation' '
77 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040078 test_config_global protocol.file.allow always &&
Stefan Bellerabed0002016-05-26 14:59:43 -070079 git config -f .gitmodules submodule.sub.shallow true &&
80 git add .gitmodules &&
Ville Skyttä64127572017-06-25 13:20:41 +030081 git commit -m "recommend shallow for sub" &&
Stefan Bellerabed0002016-05-26 14:59:43 -070082 git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
83 (
84 cd super_clone &&
85 git log --oneline >lines &&
86 test_line_count = 4 lines
87 ) &&
88 (
89 cd super_clone/sub &&
90 git log --oneline >lines &&
91 test_line_count = 1 lines
92 )
93'
94
95test_expect_success 'get unshallow recommended shallow submodule' '
96 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -040097 test_config_global protocol.file.allow always &&
Stefan Bellerabed0002016-05-26 14:59:43 -070098 git clone --no-local "file://$pwd/." super_clone &&
99 (
100 cd super_clone &&
101 git submodule update --init --no-recommend-shallow &&
102 git log --oneline >lines &&
103 test_line_count = 4 lines
104 ) &&
105 (
106 cd super_clone/sub &&
107 git log --oneline >lines &&
108 test_line_count = 3 lines
109 )
110'
111
112test_expect_success 'clone follows non shallow recommendation' '
113 test_when_finished "rm -rf super_clone" &&
Taylor Blau225d2d52022-07-29 15:21:06 -0400114 test_config_global protocol.file.allow always &&
Stefan Bellerabed0002016-05-26 14:59:43 -0700115 git config -f .gitmodules submodule.sub.shallow false &&
116 git add .gitmodules &&
Ville Skyttä64127572017-06-25 13:20:41 +0300117 git commit -m "recommend non shallow for sub" &&
Stefan Bellerabed0002016-05-26 14:59:43 -0700118 git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
119 (
120 cd super_clone &&
121 git log --oneline >lines &&
122 test_line_count = 5 lines
123 ) &&
124 (
125 cd super_clone/sub &&
126 git log --oneline >lines &&
127 test_line_count = 3 lines
128 )
129'
130
Stefan Bellerd22eb042016-04-25 18:12:27 -0700131test_done