#!/bin/sh global test_description := ''test local clone'' source ./test-lib.sh proc repo_is_hardlinked { find "$1/objects" -type f -links 1 >output && test_line_count = 0 output } test_expect_success 'preparing origin repository' ' : >file && git add . && git commit -m1 && git clone --bare . a.git && git clone --bare . x && test "$(cd a.git && git config --bool core.bare)" = true && test "$(cd x && git config --bool core.bare)" = true && git bundle create b1.bundle --all && git bundle create b2.bundle master && mkdir dir && cp b1.bundle dir/b3 && cp b1.bundle b4 ' test_expect_success 'local clone without .git suffix' ' git clone -l -s a b && (cd b && test "$(git config --bool core.bare)" = false && git fetch) ' test_expect_success 'local clone with .git suffix' ' git clone -l -s a.git c && (cd c && git fetch) ' test_expect_success 'local clone from x' ' git clone -l -s x y && (cd y && git fetch) ' test_expect_success 'local clone from x.git that does not exist' ' test_must_fail git clone -l -s x.git z ' test_expect_success 'With -no-hardlinks, local will make a copy' ' git clone --bare --no-hardlinks x w && ! repo_is_hardlinked w ' test_expect_success 'Even without -l, local will make a hardlink' ' rm -fr w && git clone -l --bare x w && repo_is_hardlinked w ' test_expect_success 'local clone of repo with nonexistent ref in HEAD' ' echo "ref: refs/heads/nonexistent" > a.git/HEAD && git clone a d && (cd d && git fetch && test ! -e .git/refs/remotes/origin/HEAD) ' test_expect_success 'bundle clone without .bundle suffix' ' git clone dir/b3 && (cd b3 && git fetch) ' test_expect_success 'bundle clone with .bundle suffix' ' git clone b1.bundle && (cd b1 && git fetch) ' test_expect_success 'bundle clone from b4' ' git clone b4 bdl && (cd bdl && git fetch) ' test_expect_success 'bundle clone from b4.bundle that does not exist' ' test_must_fail git clone b4.bundle bb ' test_expect_success 'bundle clone with nonexistent HEAD' ' git clone b2.bundle b2 && (cd b2 && git fetch && test_must_fail git rev-parse --verify refs/heads/master) ' test_expect_success 'clone empty repository' ' mkdir empty && (cd empty && git init && git config receive.denyCurrentBranch warn) && git clone empty empty-clone && test_tick && (cd empty-clone echo "content" >> foo && git add foo && git commit -m "Initial commit" && git push origin master && expected=$(git rev-parse master) && actual=$(git --git-dir=../empty/.git rev-parse master) && test $actual = $expected) ' test_expect_success 'clone empty repository, and then push should not segfault.' ' rm -fr empty/ empty-clone/ && mkdir empty && (cd empty && git init) && git clone empty empty-clone && (cd empty-clone && test_must_fail git push) ' test_expect_success 'cloning non-existent directory fails' ' rm -rf does-not-exist && test_must_fail git clone does-not-exist ' test_expect_success 'cloning non-git directory fails' ' rm -rf not-a-git-repo not-a-git-repo-clone && mkdir not-a-git-repo && test_must_fail git clone not-a-git-repo not-a-git-repo-clone ' test_expect_success 'cloning file:// does not hardlink' ' git clone --bare file://"$(pwd)"/a non-local && ! repo_is_hardlinked non-local ' test_expect_success 'cloning a local path with --no-local does not hardlink' ' git clone --bare --no-local a force-nonlocal && ! repo_is_hardlinked force-nonlocal ' test_expect_success 'cloning locally respects "-u" for fetching refs' ' test_must_fail git clone --bare -u false a should_not_work.git ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test local clone">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: repo_is_hardlinked body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(find)} {(DQ ($ VSub_Number "$1") (/objects))} {(-type)} {(f)} {(-links)} {(1)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(output)} spids:[36])] ) (C {(test_line_count)} {(Lit_Other "=")} {(0)} {(output)}) ] op_id: Op_DAmp ) ] spids: [18] ) spids: [14 17] ) (C {(test_expect_success)} {(SQ <"preparing origin repository">)} { (SQ <"\n"> <"\t: >file && git add . && git commit -m1 &&\n"> <"\tgit clone --bare . a.git &&\n"> <"\tgit clone --bare . x &&\n"> <"\ttest \"$(cd a.git && git config --bool core.bare)\" = true &&\n"> <"\ttest \"$(cd x && git config --bool core.bare)\" = true &&\n"> <"\tgit bundle create b1.bundle --all &&\n"> <"\tgit bundle create b2.bundle master &&\n"> <"\tmkdir dir &&\n"> <"\tcp b1.bundle dir/b3 &&\n"> <"\tcp b1.bundle b4\n"> ) } ) (C {(test_expect_success)} {(SQ <"local clone without .git suffix">)} { (SQ <"\n"> <"\tgit clone -l -s a b &&\n"> <"\t(cd b &&\n"> <"\ttest \"$(git config --bool core.bare)\" = false &&\n"> <"\tgit fetch)\n"> ) } ) (C {(test_expect_success)} {(SQ <"local clone with .git suffix">)} {(SQ <"\n"> <"\tgit clone -l -s a.git c &&\n"> <"\t(cd c && git fetch)\n">)} ) (C {(test_expect_success)} {(SQ <"local clone from x">)} {(SQ <"\n"> <"\tgit clone -l -s x y &&\n"> <"\t(cd y && git fetch)\n">)} ) (C {(test_expect_success)} {(SQ <"local clone from x.git that does not exist">)} {(SQ <"\n"> <"\ttest_must_fail git clone -l -s x.git z\n">)} ) (C {(test_expect_success)} {(SQ <"With -no-hardlinks, local will make a copy">)} {(SQ <"\n"> <"\tgit clone --bare --no-hardlinks x w &&\n"> <"\t! repo_is_hardlinked w\n">)} ) (C {(test_expect_success)} {(SQ <"Even without -l, local will make a hardlink">)} { (SQ <"\n"> <"\trm -fr w &&\n"> <"\tgit clone -l --bare x w &&\n"> <"\trepo_is_hardlinked w\n">) } ) (C {(test_expect_success)} {(SQ <"local clone of repo with nonexistent ref in HEAD">)} { (SQ <"\n"> <"\techo \"ref: refs/heads/nonexistent\" > a.git/HEAD &&\n"> <"\tgit clone a d &&\n"> <"\t(cd d &&\n"> <"\tgit fetch &&\n"> <"\ttest ! -e .git/refs/remotes/origin/HEAD)\n"> ) } ) (C {(test_expect_success)} {(SQ <"bundle clone without .bundle suffix">)} {(SQ <"\n"> <"\tgit clone dir/b3 &&\n"> <"\t(cd b3 && git fetch)\n">)} ) (C {(test_expect_success)} {(SQ <"bundle clone with .bundle suffix">)} {(SQ <"\n"> <"\tgit clone b1.bundle &&\n"> <"\t(cd b1 && git fetch)\n">)} ) (C {(test_expect_success)} {(SQ <"bundle clone from b4">)} {(SQ <"\n"> <"\tgit clone b4 bdl &&\n"> <"\t(cd bdl && git fetch)\n">)} ) (C {(test_expect_success)} {(SQ <"bundle clone from b4.bundle that does not exist">)} {(SQ <"\n"> <"\ttest_must_fail git clone b4.bundle bb\n">)} ) (C {(test_expect_success)} {(SQ <"bundle clone with nonexistent HEAD">)} { (SQ <"\n"> <"\tgit clone b2.bundle b2 &&\n"> <"\t(cd b2 &&\n"> <"\tgit fetch &&\n"> <"\ttest_must_fail git rev-parse --verify refs/heads/master)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone empty repository">)} { (SQ <"\n"> <"\tmkdir empty &&\n"> <"\t(cd empty &&\n"> <"\t git init &&\n"> <"\t git config receive.denyCurrentBranch warn) &&\n"> <"\tgit clone empty empty-clone &&\n"> <"\ttest_tick &&\n"> <"\t(cd empty-clone\n"> <"\t echo \"content\" >> foo &&\n"> <"\t git add foo &&\n"> <"\t git commit -m \"Initial commit\" &&\n"> <"\t git push origin master &&\n"> <"\t expected=$(git rev-parse master) &&\n"> <"\t actual=$(git --git-dir=../empty/.git rev-parse master) &&\n"> <"\t test $actual = $expected)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone empty repository, and then push should not segfault.">)} { (SQ <"\n"> <"\trm -fr empty/ empty-clone/ &&\n"> <"\tmkdir empty &&\n"> <"\t(cd empty && git init) &&\n"> <"\tgit clone empty empty-clone &&\n"> <"\t(cd empty-clone &&\n"> <"\ttest_must_fail git push)\n"> ) } ) (C {(test_expect_success)} {(SQ <"cloning non-existent directory fails">)} {(SQ <"\n"> <"\trm -rf does-not-exist &&\n"> <"\ttest_must_fail git clone does-not-exist\n">)} ) (C {(test_expect_success)} {(SQ <"cloning non-git directory fails">)} { (SQ <"\n"> <"\trm -rf not-a-git-repo not-a-git-repo-clone &&\n"> <"\tmkdir not-a-git-repo &&\n"> <"\ttest_must_fail git clone not-a-git-repo not-a-git-repo-clone\n"> ) } ) (C {(test_expect_success)} {(SQ <"cloning file:// does not hardlink">)} { (SQ <"\n"> <"\tgit clone --bare file://\"$(pwd)\"/a non-local &&\n"> <"\t! repo_is_hardlinked non-local\n"> ) } ) (C {(test_expect_success)} {(SQ <"cloning a local path with --no-local does not hardlink">)} { (SQ <"\n"> <"\tgit clone --bare --no-local a force-nonlocal &&\n"> <"\t! repo_is_hardlinked force-nonlocal\n"> ) } ) (C {(test_expect_success)} {(SQ <"cloning locally respects \"-u\" for fetching refs">)} {(SQ <"\n"> <"\ttest_must_fail git clone --bare -u false a should_not_work.git\n">)} ) (C {(test_done)}) ] )