Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test shallow cloning of repos with submodules' |
| 4 | |
Ævar Arnfjörð Bjarmason | dd4143e | 2022-11-08 19:17:47 +0100 | [diff] [blame] | 5 | TEST_PASSES_SANITIZE_LEAK=true |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 6 | . ./test-lib.sh |
| 7 | |
| 8 | pwd=$(pwd) |
| 9 | |
| 10 | test_expect_success 'setup' ' |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 11 | git checkout -b main && |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 12 | 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 | |
| 26 | test_expect_success 'nonshallow clone implies nonshallow submodule' ' |
| 27 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 28 | test_config_global protocol.file.allow always && |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 29 | git clone --recurse-submodules "file://$pwd/." super_clone && |
Stefan Beller | 5819c2e | 2016-06-20 10:21:18 -0700 | [diff] [blame] | 30 | 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 Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 34 | ' |
| 35 | |
Junio C Hamano | 18a74a0 | 2016-06-19 13:51:56 -0700 | [diff] [blame] | 36 | test_expect_success 'shallow clone with shallow submodule' ' |
| 37 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 38 | test_config_global protocol.file.allow always && |
Junio C Hamano | 18a74a0 | 2016-06-19 13:51:56 -0700 | [diff] [blame] | 39 | git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone && |
Stefan Beller | 5819c2e | 2016-06-20 10:21:18 -0700 | [diff] [blame] | 40 | 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 Hamano | 18a74a0 | 2016-06-19 13:51:56 -0700 | [diff] [blame] | 44 | ' |
| 45 | |
| 46 | test_expect_success 'shallow clone does not imply shallow submodule' ' |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 47 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 48 | test_config_global protocol.file.allow always && |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 49 | git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone && |
Stefan Beller | 5819c2e | 2016-06-20 10:21:18 -0700 | [diff] [blame] | 50 | 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 Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 54 | ' |
| 55 | |
| 56 | test_expect_success 'shallow clone with non shallow submodule' ' |
| 57 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 58 | test_config_global protocol.file.allow always && |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 59 | git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone && |
Stefan Beller | 5819c2e | 2016-06-20 10:21:18 -0700 | [diff] [blame] | 60 | 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 Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 64 | ' |
| 65 | |
| 66 | test_expect_success 'non shallow clone with shallow submodule' ' |
| 67 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 68 | test_config_global protocol.file.allow always && |
Stefan Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 69 | git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone && |
Stefan Beller | 5819c2e | 2016-06-20 10:21:18 -0700 | [diff] [blame] | 70 | 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 Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 74 | ' |
| 75 | |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 76 | test_expect_success 'clone follows shallow recommendation' ' |
| 77 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 78 | test_config_global protocol.file.allow always && |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 79 | git config -f .gitmodules submodule.sub.shallow true && |
| 80 | git add .gitmodules && |
Ville Skyttä | 6412757 | 2017-06-25 13:20:41 +0300 | [diff] [blame] | 81 | git commit -m "recommend shallow for sub" && |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 82 | 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 | |
| 95 | test_expect_success 'get unshallow recommended shallow submodule' ' |
| 96 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 97 | test_config_global protocol.file.allow always && |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 98 | 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 | |
| 112 | test_expect_success 'clone follows non shallow recommendation' ' |
| 113 | test_when_finished "rm -rf super_clone" && |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 114 | test_config_global protocol.file.allow always && |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 115 | git config -f .gitmodules submodule.sub.shallow false && |
| 116 | git add .gitmodules && |
Ville Skyttä | 6412757 | 2017-06-25 13:20:41 +0300 | [diff] [blame] | 117 | git commit -m "recommend non shallow for sub" && |
Stefan Beller | abed000 | 2016-05-26 14:59:43 -0700 | [diff] [blame] | 118 | 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 Beller | d22eb04 | 2016-04-25 18:12:27 -0700 | [diff] [blame] | 131 | test_done |