git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / t5615-alternate-env.sh
| 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_expect_success 'packs across sources are checked before loose objects' ' |
| 92 | # Regression test for a performance issue in which an object that |
| 93 | # resides in an alternate as a packed object caused a spurious loose |
| 94 | # object lookup (a filesystem stat) on the main object store before the |
| 95 | # alternate packfile was consulted. Reading such an object must resolve |
| 96 | # to the alternate packfile, never to a loose copy in the main store. |
| 97 | # |
| 98 | # Build an alternate whose object "B" is stored as a delta in a |
| 99 | # packfile. git deltifies successive versions of a tracked file, so the |
| 100 | # older, shorter blob "B" becomes a delta against the newer, longer |
| 101 | # blob "O". A loose object has no delta base, so %(deltabase) tells us |
| 102 | # which store answered the read: the alternate pack (O) or a loose copy |
| 103 | # (the zero oid). |
| 104 | git init alt-src && |
| 105 | test_seq 1 200 >alt-src/file && |
| 106 | git -C alt-src add file && |
| 107 | git -C alt-src commit -q -m base && |
| 108 | B=$(git -C alt-src rev-parse HEAD:file) && |
| 109 | git -C alt-src cat-file blob "$B" >b-content && |
| 110 | test_seq 1 210 >alt-src/file && |
| 111 | git -C alt-src add file && |
| 112 | git -C alt-src commit -q -m more && |
| 113 | O=$(git -C alt-src rev-parse HEAD:file) && |
| 114 | git -C alt-src repack -adf --window=10 --depth=50 && |
| 115 | |
| 116 | # Precondition: in the alternate, B is a delta based on O. |
| 117 | echo "$B" >in && |
| 118 | echo "$O" >expect && |
| 119 | git -C alt-src cat-file --batch-check="%(deltabase)" <in >actual && |
| 120 | test_cmp expect actual && |
| 121 | |
| 122 | # Main repo: write B as a loose object, before any alternate is active. |
| 123 | git init main && |
| 124 | git -C main hash-object -w --stdin <b-content >/dev/null && |
| 125 | test_path_is_file "main/.git/objects/$(test_oid_to_path "$B")" && |
| 126 | |
| 127 | # With the alternate active, B must resolve to the alternate packfile |
| 128 | # (deltabase O), not to the main store loose copy (deltabase zero oid). |
| 129 | GIT_ALTERNATE_OBJECT_DIRECTORIES="$PWD/alt-src/.git/objects" \ |
| 130 | git -C main cat-file --batch-check="%(deltabase)" <in >actual && |
| 131 | test_cmp expect actual |
| 132 | ' |
| 133 | |
| 134 | test_done |