| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='selecting remote repo in ambiguous cases' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | reset() { |
| 8 | rm -rf foo foo.git fetch clone |
| 9 | } |
| 10 | |
| 11 | make_tree() { |
| 12 | git init "$1" && |
| 13 | (cd "$1" && test_commit "$1") |
| 14 | } |
| 15 | |
| 16 | make_bare() { |
| 17 | git init --bare "$1" && |
| 18 | (cd "$1" && |
| 19 | tree=$(git hash-object -w -t tree /dev/null) && |
| 20 | commit=$(echo "$1" | git commit-tree $tree) && |
| 21 | git update-ref HEAD $commit |
| 22 | ) |
| 23 | } |
| 24 | |
| 25 | get() { |
| 26 | git init --bare fetch && |
| 27 | (cd fetch && git fetch "../$1") && |
| 28 | git clone "$1" clone |
| 29 | } |
| 30 | |
| 31 | check() { |
| 32 | echo "$1" >expect && |
| 33 | (cd fetch && git log -1 --format=%s FETCH_HEAD) >actual.fetch && |
| 34 | (cd clone && git log -1 --format=%s HEAD) >actual.clone && |
| 35 | test_cmp expect actual.fetch && |
| 36 | test_cmp expect actual.clone |
| 37 | } |
| 38 | |
| 39 | test_expect_success 'find .git dir in worktree' ' |
| 40 | reset && |
| 41 | make_tree foo && |
| 42 | get foo && |
| 43 | check foo |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'automagically add .git suffix' ' |
| 47 | reset && |
| 48 | make_bare foo.git && |
| 49 | get foo && |
| 50 | check foo.git |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'automagically add .git suffix to worktree' ' |
| 54 | reset && |
| 55 | make_tree foo.git && |
| 56 | get foo && |
| 57 | check foo.git |
| 58 | ' |
| 59 | |
| 60 | test_expect_success 'prefer worktree foo over bare foo.git' ' |
| 61 | reset && |
| 62 | make_tree foo && |
| 63 | make_bare foo.git && |
| 64 | get foo && |
| 65 | check foo |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'prefer bare foo over bare foo.git' ' |
| 69 | reset && |
| 70 | make_bare foo && |
| 71 | make_bare foo.git && |
| 72 | get foo && |
| 73 | check foo |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'disambiguate with full foo.git' ' |
| 77 | reset && |
| 78 | make_bare foo && |
| 79 | make_bare foo.git && |
| 80 | get foo.git && |
| 81 | check foo.git |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'we are not fooled by non-git foo directory' ' |
| 85 | reset && |
| 86 | make_bare foo.git && |
| 87 | mkdir foo && |
| 88 | get foo && |
| 89 | check foo.git |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'prefer inner .git over outer bare' ' |
| 93 | reset && |
| 94 | make_tree foo && |
| 95 | make_bare foo.git && |
| 96 | mv foo/.git foo.git && |
| 97 | get foo.git && |
| 98 | check foo |
| 99 | ' |
| 100 | |
| 101 | test_done |