git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / t7706-repack-drop-filtered.sh
| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git repack --drop-filtered enumerates filtered promisor blobs' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | # Delete a loose or packed object from "repo". |
| 8 | delete_object () { |
| 9 | local repo="$1" && |
| 10 | local obj="$2" && |
| 11 | local path="$repo/.git/objects/$(test_oid_to_path "$obj")" && |
| 12 | rm "$path" |
| 13 | } |
| 14 | |
| 15 | # Pack the objects into a promisor pack inside "repo". It is a pack |
| 16 | # accompanied by an empty ".promisor" marker file. Objects |
| 17 | # in such a pack are treated as recoverable from the promisor remote. |
| 18 | pack_as_from_promisor () { |
| 19 | HASH=$(git -C repo pack-objects .git/objects/pack/pack) && |
| 20 | >repo/.git/objects/pack/pack-$HASH.promisor && |
| 21 | echo $HASH |
| 22 | } |
| 23 | |
| 24 | # Write a blob of $1 bytes into "repo", record it as coming from the |
| 25 | # promisor remote, and remove the loose copy so the object is only |
| 26 | # present in the promisor pack. |
| 27 | promisor_blob () { |
| 28 | test-tool genrandom "$1" "$2" >blob_content && |
| 29 | OID=$(git -C repo hash-object -w --stdin <blob_content) && |
| 30 | printf "%s\n" "$OID" | pack_as_from_promisor >/dev/null && |
| 31 | delete_object repo "$OID" && |
| 32 | echo "$OID" |
| 33 | } |
| 34 | |
| 35 | # Check option validation before any promisor walk |
| 36 | test_expect_success 'setup plain repo for validation' ' |
| 37 | git init plain && |
| 38 | test_commit -C plain initial && |
| 39 | git clone --bare plain plain.git && |
| 40 | git -C plain.git repack -a -d |
| 41 | ' |
| 42 | |
| 43 | test_expect_success '--drop-filtered requires --filter' ' |
| 44 | test_must_fail git -C plain.git repack --drop-filtered --dry-run -a 2>err && |
| 45 | test_grep "drop-filtered requires --filter" err |
| 46 | ' |
| 47 | |
| 48 | test_expect_success '--drop-filtered cannot be used with --filter-to' ' |
| 49 | test_must_fail git -C plain.git repack --drop-filtered \ |
| 50 | --filter=blob:limit=1k --filter-to=./filter-out 2>err && |
| 51 | test_grep "options .--drop-filtered. and .--filter-to. cannot be used together" err |
| 52 | ' |
| 53 | |
| 54 | test_expect_success '--dry-run only takes effect with --drop-filtered' ' |
| 55 | test_must_fail git -C plain.git repack --dry-run 2>err && |
| 56 | test_grep "dry-run only takes effect with --drop-filtered" err |
| 57 | ' |
| 58 | |
| 59 | test_expect_success '--drop-filtered requires -a' ' |
| 60 | test_must_fail git -C plain.git repack --drop-filtered \ |
| 61 | --filter=blob:limit=1k --dry-run 2>err && |
| 62 | test_grep "drop-filtered requires -a" err |
| 63 | ' |
| 64 | |
| 65 | test_expect_success '--drop-filtered fails with --write-bitmap-index' ' |
| 66 | test_must_fail git -C plain.git repack --drop-filtered \ |
| 67 | --filter=blob:limit=1k --dry-run -a -b 2>err && |
| 68 | test_grep "options .--drop-filtered. and .--write-bitmap-index. cannot be used together" err |
| 69 | ' |
| 70 | |
| 71 | test_expect_success '--drop-filtered rejects explicit -b even when repack.writeBitmaps=true' ' |
| 72 | test_must_fail git -C plain.git -c repack.writeBitmaps=true \ |
| 73 | repack --drop-filtered --filter=blob:limit=1k --dry-run -a -b 2>err && |
| 74 | test_grep "options .--drop-filtered. and .--write-bitmap-index. cannot be used together" err |
| 75 | ' |
| 76 | |
| 77 | test_expect_success '--drop-filtered fails without a promisor remote' ' |
| 78 | test_must_fail git -C plain.git repack --drop-filtered \ |
| 79 | --filter=blob:limit=1k --dry-run -a 2>err && |
| 80 | test_grep "drop-filtered requires a promisor remote" err |
| 81 | ' |
| 82 | |
| 83 | # Enumeration tests using promisor pack |
| 84 | test_expect_success 'setup repo with a promisor remote' ' |
| 85 | rm -rf repo && |
| 86 | test_create_repo repo && |
| 87 | test_commit -C repo base && |
| 88 | |
| 89 | # Mark the repo as a partial clone with a promisor remote so the |
| 90 | # promisor walk and the safety guard are satisfied. |
| 91 | git -C repo config core.repositoryformatversion 1 && |
| 92 | git -C repo config extensions.partialclone origin && |
| 93 | git -C repo config remote.origin.promisor true && |
| 94 | git -C repo config remote.origin.url "." && |
| 95 | |
| 96 | BIG=$(promisor_blob big 3072) && |
| 97 | SMALL=$(promisor_blob small 512) && |
| 98 | echo "$BIG" >big_oid && |
| 99 | echo "$SMALL" >small_oid |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'promisor blob over the threshold is listed' ' |
| 103 | BIG=$(cat big_oid) && |
| 104 | SMALL=$(cat small_oid) && |
| 105 | |
| 106 | git -C repo -c repack.writeBitmaps=false \ |
| 107 | repack --drop-filtered --filter=blob:limit=1k --dry-run -a >out && |
| 108 | |
| 109 | test_grep "$BIG" out && |
| 110 | test_grep ! "$SMALL" out |
| 111 | ' |
| 112 | |
| 113 | test_expect_success 'locally created blob is never listed' ' |
| 114 | BIG=$(cat big_oid) && |
| 115 | |
| 116 | # Large blob that exists only locally must never be a drop candidate. |
| 117 | # Dropping it would be unrecoverable. |
| 118 | test-tool genrandom local 4096 >local_content && |
| 119 | LOCAL=$(git -C repo hash-object -w --stdin <local_content) && |
| 120 | |
| 121 | git -C repo -c repack.writeBitmaps=false \ |
| 122 | repack --drop-filtered --filter=blob:limit=1k --dry-run -a >out && |
| 123 | |
| 124 | test_grep "$BIG" out && |
| 125 | test_grep ! "$LOCAL" out |
| 126 | ' |
| 127 | |
| 128 | test_expect_success '--dry-run does not remove the filtered objects' ' |
| 129 | BIG=$(cat big_oid) && |
| 130 | |
| 131 | git -C repo -c repack.writeBitmaps=false \ |
| 132 | repack --drop-filtered --filter=blob:limit=1k --dry-run -a >out && |
| 133 | |
| 134 | # Candidate blob must still be present after a dry run. |
| 135 | git -C repo cat-file -e "$BIG" |
| 136 | ' |
| 137 | |
| 138 | test_expect_success '--dry-run leaves the pack directory untouched' ' |
| 139 | BIG=$(cat big_oid) && |
| 140 | packdir=repo/.git/objects/pack && |
| 141 | |
| 142 | for opt in "" -d |
| 143 | do |
| 144 | ls $packdir >before && |
| 145 | |
| 146 | git -C repo -c repack.writeBitmaps=false \ |
| 147 | repack --drop-filtered --filter=blob:limit=1k \ |
| 148 | --dry-run -a $opt >out && |
| 149 | |
| 150 | ls $packdir >after && |
| 151 | test_cmp before after && |
| 152 | test_grep "$BIG" out && |
| 153 | git -C repo cat-file -e "$BIG" || return 1 |
| 154 | done |
| 155 | ' |
| 156 | |
| 157 | test_expect_success '--drop-filtered removes the promisor blob locally' ' |
| 158 | BIG=$(cat big_oid) && |
| 159 | SMALL=$(cat small_oid) && |
| 160 | |
| 161 | git -C repo -c repack.writeBitmaps=false \ |
| 162 | repack --drop-filtered --filter=blob:limit=1k -a && |
| 163 | |
| 164 | git -C repo cat-file --batch-all-objects --batch-check="%(objectname)" >present && |
| 165 | test_grep ! "$BIG" present && |
| 166 | test_grep "$SMALL" present |
| 167 | ' |
| 168 | |
| 169 | test_expect_success '--drop-filtered refuses when a merge is in progress' ' |
| 170 | test_when_finished "git -C repo merge --abort || :" && |
| 171 | |
| 172 | # Create a conflicting merge so wt_status reports it. |
| 173 | git -C repo checkout -B mergebase base && |
| 174 | echo one >repo/conflict.txt && |
| 175 | git -C repo add conflict.txt && |
| 176 | git -C repo commit -m one && |
| 177 | |
| 178 | git -C repo checkout -B mergeother base && |
| 179 | echo two >repo/conflict.txt && |
| 180 | git -C repo add conflict.txt && |
| 181 | git -C repo commit -m two && |
| 182 | |
| 183 | test_must_fail git -C repo merge mergebase && |
| 184 | |
| 185 | test_must_fail git -C repo -c repack.writeBitmaps=false \ |
| 186 | repack --drop-filtered --filter=blob:limit=1k --dry-run -a 2>err && |
| 187 | test_grep "in progress" err |
| 188 | ' |
| 189 | |
| 190 | test_expect_success '--drop-filtered refuses to drop an index-referenced blob' ' |
| 191 | # Create a large blob, add it to the index and make it a promisor object |
| 192 | # so the index references it and enumeration picks it up. |
| 193 | test-tool genrandom idx 4096 >repo/tracked-big.bin && |
| 194 | git -C repo add tracked-big.bin && |
| 195 | OID=$(git -C repo rev-parse :tracked-big.bin) && |
| 196 | printf "%s\n" "$OID" | pack_as_from_promisor >/dev/null && |
| 197 | delete_object repo "$OID" && |
| 198 | |
| 199 | test_must_fail git -C repo -c repack.writeBitmaps=false \ |
| 200 | repack --drop-filtered --filter=blob:limit=1k --dry-run -a 2>err && |
| 201 | test_grep "referenced by the current index" err |
| 202 | ' |
| 203 | |
| 204 | test_done |