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