1#!/bin/sh23test_description='Test shallow cloning of repos with submodules'45. ./test-lib.sh67pwd=$(pwd)89test_expect_success 'setup' '10git checkout -b master &&11test_commit commit1 &&12test_commit commit2 &&13mkdir sub &&14(15cd sub &&16git init &&17test_commit subcommit1 &&18test_commit subcommit2 &&19test_commit subcommit320) &&21git submodule add "file://$pwd/sub" sub &&22git commit -m "add submodule"23'2425test_expect_success 'nonshallow clone implies nonshallow submodule' '26test_when_finished "rm -rf super_clone" &&27git clone --recurse-submodules "file://$pwd/." super_clone &&28(29cd super_clone &&30git log --oneline >lines &&31test_line_count = 3 lines32) &&33(34cd super_clone/sub &&35git log --oneline >lines &&36test_line_count = 3 lines37)38'3940test_expect_success 'shallow clone implies shallow submodule' '41test_when_finished "rm -rf super_clone" &&42git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&43(44cd super_clone &&45git log --oneline >lines &&46test_line_count = 2 lines47) &&48(49cd super_clone/sub &&50git log --oneline >lines &&51test_line_count = 1 lines52)53'5455test_expect_success 'shallow clone with non shallow submodule' '56test_when_finished "rm -rf super_clone" &&57git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&58(59cd super_clone &&60git log --oneline >lines &&61test_line_count = 2 lines62) &&63(64cd super_clone/sub &&65git log --oneline >lines &&66test_line_count = 3 lines67)68'6970test_expect_success 'non shallow clone with shallow submodule' '71test_when_finished "rm -rf super_clone" &&72git clone --recurse-submodules --no-local --shallow-submodules "file://$pwd/." super_clone &&73(74cd super_clone &&75git log --oneline >lines &&76test_line_count = 3 lines77) &&78(79cd super_clone/sub &&80git log --oneline >lines &&81test_line_count = 1 lines82)83'8485test_expect_success 'clone follows shallow recommendation' '86test_when_finished "rm -rf super_clone" &&87git config -f .gitmodules submodule.sub.shallow true &&88git add .gitmodules &&89git commit -m "recommed shallow for sub" &&90git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&91(92cd super_clone &&93git log --oneline >lines &&94test_line_count = 4 lines95) &&96(97cd super_clone/sub &&98git log --oneline >lines &&99test_line_count = 1 lines100)101'102103test_expect_success 'get unshallow recommended shallow submodule' '104test_when_finished "rm -rf super_clone" &&105git clone --no-local "file://$pwd/." super_clone &&106(107cd super_clone &&108git submodule update --init --no-recommend-shallow &&109git log --oneline >lines &&110test_line_count = 4 lines111) &&112(113cd super_clone/sub &&114git log --oneline >lines &&115test_line_count = 3 lines116)117'118119test_expect_success 'clone follows non shallow recommendation' '120test_when_finished "rm -rf super_clone" &&121git config -f .gitmodules submodule.sub.shallow false &&122git add .gitmodules &&123git commit -m "recommed non shallow for sub" &&124git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&125(126cd super_clone &&127git log --oneline >lines &&128test_line_count = 5 lines129) &&130(131cd super_clone/sub &&132git log --oneline >lines &&133test_line_count = 3 lines134)135'136137test_done