t / t6112-rev-list-filters-objects.shon commit doc/config: do a better job of introducing 'worktree.guessRemote' (b4583d5)
   1#!/bin/sh
   2
   3test_description='git rev-list using object filtering'
   4
   5. ./test-lib.sh
   6
   7# Test the blob:none filter.
   8
   9test_expect_success 'setup r1' '
  10        echo "{print \$1}" >print_1.awk &&
  11        echo "{print \$2}" >print_2.awk &&
  12
  13        git init r1 &&
  14        for n in 1 2 3 4 5
  15        do
  16                echo "This is file: $n" > r1/file.$n
  17                git -C r1 add file.$n
  18                git -C r1 commit -m "$n"
  19        done
  20'
  21
  22test_expect_success 'verify blob:none omits all 5 blobs' '
  23        git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
  24                >ls_files_result &&
  25        awk -f print_2.awk ls_files_result |
  26        sort >expected &&
  27
  28        git -C r1 rev-list --quiet --objects --filter-print-omitted \
  29                --filter=blob:none HEAD >revs &&
  30        awk -f print_1.awk revs |
  31        sed "s/~//" |
  32        sort >observed &&
  33
  34        test_cmp expected observed
  35'
  36
  37test_expect_success 'verify emitted+omitted == all' '
  38        git -C r1 rev-list --objects HEAD >revs &&
  39        awk -f print_1.awk revs |
  40        sort >expected &&
  41
  42        git -C r1 rev-list --objects --filter-print-omitted --filter=blob:none \
  43                HEAD >revs &&
  44        awk -f print_1.awk revs |
  45        sed "s/~//" |
  46        sort >observed &&
  47
  48        test_cmp expected observed
  49'
  50
  51
  52# Test blob:limit=<n>[kmg] filter.
  53# We boundary test around the size parameter.  The filter is strictly less than
  54# the value, so size 500 and 1000 should have the same results, but 1001 should
  55# filter more.
  56
  57test_expect_success 'setup r2' '
  58        git init r2 &&
  59        for n in 1000 10000
  60        do
  61                printf "%"$n"s" X > r2/large.$n
  62                git -C r2 add large.$n
  63                git -C r2 commit -m "$n"
  64        done
  65'
  66
  67test_expect_success 'verify blob:limit=500 omits all blobs' '
  68        git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
  69        awk -f print_2.awk ls_files_result |
  70        sort >expected &&
  71
  72        git -C r2 rev-list --quiet --objects --filter-print-omitted \
  73                --filter=blob:limit=500 HEAD >revs &&
  74        awk -f print_1.awk revs |
  75        sed "s/~//" |
  76        sort >observed &&
  77
  78        test_cmp expected observed
  79'
  80
  81test_expect_success 'verify emitted+omitted == all' '
  82        git -C r2 rev-list --objects HEAD >revs &&
  83        awk -f print_1.awk revs |
  84        sort >expected &&
  85
  86        git -C r2 rev-list --objects --filter-print-omitted \
  87                --filter=blob:limit=500 HEAD >revs &&
  88        awk -f print_1.awk revs |
  89        sed "s/~//" |
  90        sort >observed &&
  91
  92        test_cmp expected observed
  93'
  94
  95test_expect_success 'verify blob:limit=1000' '
  96        git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
  97        awk -f print_2.awk ls_files_result |
  98        sort >expected &&
  99
 100        git -C r2 rev-list --quiet --objects --filter-print-omitted \
 101                --filter=blob:limit=1000 HEAD >revs &&
 102        awk -f print_1.awk revs |
 103        sed "s/~//" |
 104        sort >observed &&
 105
 106        test_cmp expected observed
 107'
 108
 109test_expect_success 'verify blob:limit=1001' '
 110        git -C r2 ls-files -s large.10000 >ls_files_result &&
 111        awk -f print_2.awk ls_files_result |
 112        sort >expected &&
 113
 114        git -C r2 rev-list --quiet --objects --filter-print-omitted \
 115                --filter=blob:limit=1001 HEAD >revs &&
 116        awk -f print_1.awk revs |
 117        sed "s/~//" |
 118        sort >observed &&
 119
 120        test_cmp expected observed
 121'
 122
 123test_expect_success 'verify blob:limit=1k' '
 124        git -C r2 ls-files -s large.10000 >ls_files_result &&
 125        awk -f print_2.awk ls_files_result |
 126        sort >expected &&
 127
 128        git -C r2 rev-list --quiet --objects --filter-print-omitted \
 129                --filter=blob:limit=1k HEAD >revs &&
 130        awk -f print_1.awk revs |
 131        sed "s/~//" |
 132        sort >observed &&
 133
 134        test_cmp expected observed
 135'
 136
 137test_expect_success 'verify blob:limit=1m' '
 138        git -C r2 rev-list --quiet --objects --filter-print-omitted \
 139                --filter=blob:limit=1m HEAD >revs &&
 140        awk -f print_1.awk revs |
 141        sed "s/~//" |
 142        sort >observed &&
 143
 144        test_must_be_empty observed
 145'
 146
 147# Test sparse:path=<path> filter.
 148# Use a local file containing a sparse-checkout specification to filter
 149# out blobs not required for the corresponding sparse-checkout.  We do not
 150# require sparse-checkout to actually be enabled.
 151
 152test_expect_success 'setup r3' '
 153        git init r3 &&
 154        mkdir r3/dir1 &&
 155        for n in sparse1 sparse2
 156        do
 157                echo "This is file: $n" > r3/$n
 158                git -C r3 add $n
 159                echo "This is file: dir1/$n" > r3/dir1/$n
 160                git -C r3 add dir1/$n
 161        done &&
 162        git -C r3 commit -m "sparse" &&
 163        echo dir1/ >pattern1 &&
 164        echo sparse1 >pattern2
 165'
 166
 167test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
 168        git -C r3 ls-files -s sparse1 sparse2 >ls_files_result &&
 169        awk -f print_2.awk ls_files_result |
 170        sort >expected &&
 171
 172        git -C r3 rev-list --quiet --objects --filter-print-omitted \
 173                --filter=sparse:path=../pattern1 HEAD >revs &&
 174        awk -f print_1.awk revs |
 175        sed "s/~//" |
 176        sort >observed &&
 177
 178        test_cmp expected observed
 179'
 180
 181test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
 182        git -C r3 ls-files -s sparse2 dir1/sparse2 >ls_files_result &&
 183        awk -f print_2.awk ls_files_result |
 184        sort >expected &&
 185
 186        git -C r3 rev-list --quiet --objects --filter-print-omitted \
 187                --filter=sparse:path=../pattern2 HEAD >revs &&
 188        awk -f print_1.awk revs |
 189        sed "s/~//" |
 190        sort >observed &&
 191
 192        test_cmp expected observed
 193'
 194
 195# Test sparse:oid=<oid-ish> filter.
 196# Like sparse:path, but we get the sparse-checkout specification from
 197# a blob rather than a file on disk.
 198
 199test_expect_success 'setup r3 part 2' '
 200        echo dir1/ >r3/pattern &&
 201        git -C r3 add pattern &&
 202        git -C r3 commit -m "pattern"
 203'
 204
 205test_expect_success 'verify sparse:oid=OID omits top-level files' '
 206        git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
 207        awk -f print_2.awk ls_files_result |
 208        sort >expected &&
 209
 210        oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
 211
 212        git -C r3 rev-list --quiet --objects --filter-print-omitted \
 213                --filter=sparse:oid=$oid HEAD >revs &&
 214        awk -f print_1.awk revs |
 215        sed "s/~//" |
 216        sort >observed &&
 217
 218        test_cmp expected observed
 219'
 220
 221test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
 222        git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
 223        awk -f print_2.awk ls_files_result |
 224        sort >expected &&
 225
 226        git -C r3 rev-list --quiet --objects --filter-print-omitted \
 227                --filter=sparse:oid=master:pattern HEAD >revs &&
 228        awk -f print_1.awk revs |
 229        sed "s/~//" |
 230        sort >observed &&
 231
 232        test_cmp expected observed
 233'
 234
 235# Delete some loose objects and use rev-list, but WITHOUT any filtering.
 236# This models previously omitted objects that we did not receive.
 237
 238test_expect_success 'rev-list W/ --missing=print' '
 239        git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
 240                >ls_files_result &&
 241        awk -f print_2.awk ls_files_result |
 242        sort >expected &&
 243
 244        for id in `cat expected | sed "s|..|&/|"`
 245        do
 246                rm r1/.git/objects/$id
 247        done &&
 248
 249        git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&
 250        awk -f print_1.awk revs |
 251        sed "s/?//" |
 252        sort >observed &&
 253
 254        test_cmp expected observed
 255'
 256
 257test_expect_success 'rev-list W/O --missing fails' '
 258        test_must_fail git -C r1 rev-list --quiet --objects HEAD
 259'
 260
 261test_expect_success 'rev-list W/ missing=allow-any' '
 262        git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
 263'
 264
 265test_done