t / t5605-clone-local.shon commit Merge branch 'vk/p4-submit-shelve' (97c138f)
   1#!/bin/sh
   2
   3test_description='test local clone'
   4. ./test-lib.sh
   5
   6repo_is_hardlinked() {
   7        find "$1/objects" -type f -links 1 >output &&
   8        test_line_count = 0 output
   9}
  10
  11test_expect_success 'preparing origin repository' '
  12        : >file && git add . && git commit -m1 &&
  13        git clone --bare . a.git &&
  14        git clone --bare . x &&
  15        test "$(cd a.git && git config --bool core.bare)" = true &&
  16        test "$(cd x && git config --bool core.bare)" = true &&
  17        git bundle create b1.bundle --all &&
  18        git bundle create b2.bundle master &&
  19        mkdir dir &&
  20        cp b1.bundle dir/b3 &&
  21        cp b1.bundle b4
  22'
  23
  24test_expect_success 'local clone without .git suffix' '
  25        git clone -l -s a b &&
  26        (cd b &&
  27        test "$(git config --bool core.bare)" = false &&
  28        git fetch)
  29'
  30
  31test_expect_success 'local clone with .git suffix' '
  32        git clone -l -s a.git c &&
  33        (cd c && git fetch)
  34'
  35
  36test_expect_success 'local clone from x' '
  37        git clone -l -s x y &&
  38        (cd y && git fetch)
  39'
  40
  41test_expect_success 'local clone from x.git that does not exist' '
  42        test_must_fail git clone -l -s x.git z
  43'
  44
  45test_expect_success 'With -no-hardlinks, local will make a copy' '
  46        git clone --bare --no-hardlinks x w &&
  47        ! repo_is_hardlinked w
  48'
  49
  50test_expect_success 'Even without -l, local will make a hardlink' '
  51        rm -fr w &&
  52        git clone -l --bare x w &&
  53        repo_is_hardlinked w
  54'
  55
  56test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
  57        echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
  58        git clone a d &&
  59        (cd d &&
  60        git fetch &&
  61        test ! -e .git/refs/remotes/origin/HEAD)
  62'
  63
  64test_expect_success 'bundle clone without .bundle suffix' '
  65        git clone dir/b3 &&
  66        (cd b3 && git fetch)
  67'
  68
  69test_expect_success 'bundle clone with .bundle suffix' '
  70        git clone b1.bundle &&
  71        (cd b1 && git fetch)
  72'
  73
  74test_expect_success 'bundle clone from b4' '
  75        git clone b4 bdl &&
  76        (cd bdl && git fetch)
  77'
  78
  79test_expect_success 'bundle clone from b4.bundle that does not exist' '
  80        test_must_fail git clone b4.bundle bb
  81'
  82
  83test_expect_success 'bundle clone with nonexistent HEAD' '
  84        git clone b2.bundle b2 &&
  85        (cd b2 &&
  86        git fetch &&
  87        test_must_fail git rev-parse --verify refs/heads/master)
  88'
  89
  90test_expect_success 'clone empty repository' '
  91        mkdir empty &&
  92        (cd empty &&
  93         git init &&
  94         git config receive.denyCurrentBranch warn) &&
  95        git clone empty empty-clone &&
  96        test_tick &&
  97        (cd empty-clone
  98         echo "content" >> foo &&
  99         git add foo &&
 100         git commit -m "Initial commit" &&
 101         git push origin master &&
 102         expected=$(git rev-parse master) &&
 103         actual=$(git --git-dir=../empty/.git rev-parse master) &&
 104         test $actual = $expected)
 105'
 106
 107test_expect_success 'clone empty repository, and then push should not segfault.' '
 108        rm -fr empty/ empty-clone/ &&
 109        mkdir empty &&
 110        (cd empty && git init) &&
 111        git clone empty empty-clone &&
 112        (cd empty-clone &&
 113        test_must_fail git push)
 114'
 115
 116test_expect_success 'cloning non-existent directory fails' '
 117        rm -rf does-not-exist &&
 118        test_must_fail git clone does-not-exist
 119'
 120
 121test_expect_success 'cloning non-git directory fails' '
 122        rm -rf not-a-git-repo not-a-git-repo-clone &&
 123        mkdir not-a-git-repo &&
 124        test_must_fail git clone not-a-git-repo not-a-git-repo-clone
 125'
 126
 127test_expect_success 'cloning file:// does not hardlink' '
 128        git clone --bare file://"$(pwd)"/a non-local &&
 129        ! repo_is_hardlinked non-local
 130'
 131
 132test_expect_success 'cloning a local path with --no-local does not hardlink' '
 133        git clone --bare --no-local a force-nonlocal &&
 134        ! repo_is_hardlinked force-nonlocal
 135'
 136
 137test_expect_success 'cloning locally respects "-u" for fetching refs' '
 138        test_must_fail git clone --bare -u false a should_not_work.git
 139'
 140
 141test_done