| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | test_description='selecting remote repo in ambiguous cases' |
| 4 | |
| 5 | . ./test-lib.shscip-shell source . . `./test-lib.sh`. |
| 6 | |
| 7 | resetscip-shell shell cgit 1.2.3+git20250818.80.3346409+git2.51.0-1 reset().() { |
| 8 | rmscip-shell system . . rm. -rf foo foo.git fetch clone |
| 9 | } |
| 10 | |
| 11 | make_treescip-shell shell cgit 1.2.3+git20250818.80.3346409+git2.51.0-1 make_tree().() { |
| 12 | gitscip-shell system . . git. init "$1" && |
| 13 | (cd "$1" && test_commit "$1") |
| 14 | } |
| 15 | |
| 16 | make_barescip-shell shell cgit 1.2.3+git20250818.80.3346409+git2.51.0-1 make_bare().() { |
| 17 | gitscip-shell system . . git. init --bare "$1" && |
| 18 | (cd "$1" && |
| 19 | tree=$(gitscip-shell system . . git. hash-object -w -t tree /dev/nullscip-shell filesystem . . `/dev/null`.) && |
| 20 | commit=$(echoscip-shell system . . echo. "$1" | gitscip-shell system . . git. commit-tree $tree) && |
| 21 | gitscip-shell system . . git. update-ref HEAD $commit |
| 22 | ) |
| 23 | } |
| 24 | |
| 25 | getscip-shell shell cgit 1.2.3+git20250818.80.3346409+git2.51.0-1 get().() { |
| 26 | gitscip-shell system . . git. init --bare fetch && |
| 27 | (cd fetch && gitscip-shell system . . git. fetch "../$1") && |
| 28 | gitscip-shell system . . git. clone "$1" clone |
| 29 | } |
| 30 | |
| 31 | checkscip-shell shell cgit 1.2.3+git20250818.80.3346409+git2.51.0-1 check().() { |
| 32 | echoscip-shell system . . echo. "$1" >expect && |
| 33 | (cd fetch && gitscip-shell system . . git. log -1 --format=%s FETCH_HEAD) >actual.fetch && |
| 34 | (cd clone && gitscip-shell system . . 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 |