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