t / t5615-alternate-env.shon commit userdiff: add a builtin pattern for dts files (3c81760)
   1#!/bin/sh
   2
   3test_description='handling of alternates in environment variables'
   4. ./test-lib.sh
   5
   6check_obj () {
   7        alt=$1; shift
   8        while read obj expect
   9        do
  10                echo "$obj" >&5 &&
  11                echo "$obj $expect" >&6
  12        done 5>input 6>expect &&
  13        GIT_ALTERNATE_OBJECT_DIRECTORIES=$alt \
  14                git "$@" cat-file --batch-check='%(objectname) %(objecttype)' \
  15                <input >actual &&
  16        test_cmp expect actual
  17}
  18
  19test_expect_success 'create alternate repositories' '
  20        git init --bare one.git &&
  21        one=$(echo one | git -C one.git hash-object -w --stdin) &&
  22        git init --bare two.git &&
  23        two=$(echo two | git -C two.git hash-object -w --stdin)
  24'
  25
  26test_expect_success 'objects inaccessible without alternates' '
  27        check_obj "" <<-EOF
  28        $one missing
  29        $two missing
  30        EOF
  31'
  32
  33test_expect_success 'access alternate via absolute path' '
  34        check_obj "$PWD/one.git/objects" <<-EOF
  35        $one blob
  36        $two missing
  37        EOF
  38'
  39
  40test_expect_success 'access multiple alternates' '
  41        check_obj "$PWD/one.git/objects:$PWD/two.git/objects" <<-EOF
  42        $one blob
  43        $two blob
  44        EOF
  45'
  46
  47# bare paths are relative from $GIT_DIR
  48test_expect_success 'access alternate via relative path (bare)' '
  49        git init --bare bare.git &&
  50        check_obj "../one.git/objects" -C bare.git <<-EOF
  51        $one blob
  52        EOF
  53'
  54
  55# non-bare paths are relative to top of worktree
  56test_expect_success 'access alternate via relative path (worktree)' '
  57        git init worktree &&
  58        check_obj "../one.git/objects" -C worktree <<-EOF
  59        $one blob
  60        EOF
  61'
  62
  63# path is computed after moving to top-level of worktree
  64test_expect_success 'access alternate via relative path (subdir)' '
  65        mkdir subdir &&
  66        check_obj "one.git/objects" -C subdir <<-EOF
  67        $one blob
  68        EOF
  69'
  70
  71# set variables outside test to avoid quote insanity; the \057 is '/',
  72# which doesn't need quoting, but just confirms that de-quoting
  73# is working.
  74quoted='"one.git\057objects"'
  75unquoted='two.git/objects'
  76test_expect_success 'mix of quoted and unquoted alternates' '
  77        check_obj "$quoted:$unquoted" <<-EOF
  78        $one blob
  79        $two blob
  80        EOF
  81'
  82
  83test_expect_success !MINGW 'broken quoting falls back to interpreting raw' '
  84        mv one.git \"one.git &&
  85        check_obj \"one.git/objects <<-EOF
  86        $one blob
  87        EOF
  88'
  89
  90test_done