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