t / t6112-rev-list-filters-objects.shon commit builtin rebase: support `--autostash` option (6defce2)
   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        cat </dev/null >expected &&
 117        git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m \
 118                | awk -f print_1.awk \
 119                | sed "s/~//" \
 120                | sort >observed &&
 121        test_cmp observed expected
 122'
 123
 124# Test sparse:path=<path> filter.
 125# Use a local file containing a sparse-checkout specification to filter
 126# out blobs not required for the corresponding sparse-checkout.  We do not
 127# require sparse-checkout to actually be enabled.
 128
 129test_expect_success 'setup r3' '
 130        git init r3 &&
 131        mkdir r3/dir1 &&
 132        for n in sparse1 sparse2
 133        do
 134                echo "This is file: $n" > r3/$n
 135                git -C r3 add $n
 136                echo "This is file: dir1/$n" > r3/dir1/$n
 137                git -C r3 add dir1/$n
 138        done &&
 139        git -C r3 commit -m "sparse" &&
 140        echo dir1/ >pattern1 &&
 141        echo sparse1 >pattern2
 142'
 143
 144test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
 145        git -C r3 ls-files -s sparse1 sparse2 \
 146                | awk -f print_2.awk \
 147                | sort >expected &&
 148        git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 \
 149                | awk -f print_1.awk \
 150                | sed "s/~//" \
 151                | sort >observed &&
 152        test_cmp observed expected
 153'
 154
 155test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
 156        git -C r3 ls-files -s sparse2 dir1/sparse2 \
 157                | awk -f print_2.awk \
 158                | sort >expected &&
 159        git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 \
 160                | awk -f print_1.awk \
 161                | sed "s/~//" \
 162                | sort >observed &&
 163        test_cmp observed expected
 164'
 165
 166# Test sparse:oid=<oid-ish> filter.
 167# Like sparse:path, but we get the sparse-checkout specification from
 168# a blob rather than a file on disk.
 169
 170test_expect_success 'setup r3 part 2' '
 171        echo dir1/ >r3/pattern &&
 172        git -C r3 add pattern &&
 173        git -C r3 commit -m "pattern"
 174'
 175
 176test_expect_success 'verify sparse:oid=OID omits top-level files' '
 177        git -C r3 ls-files -s pattern sparse1 sparse2 \
 178                | awk -f print_2.awk \
 179                | sort >expected &&
 180        oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
 181        git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid \
 182                | awk -f print_1.awk \
 183                | sed "s/~//" \
 184                | sort >observed &&
 185        test_cmp observed expected
 186'
 187
 188test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
 189        git -C r3 ls-files -s pattern sparse1 sparse2 \
 190                | awk -f print_2.awk \
 191                | sort >expected &&
 192        git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern \
 193                | awk -f print_1.awk \
 194                | sed "s/~//" \
 195                | sort >observed &&
 196        test_cmp observed expected
 197'
 198
 199# Delete some loose objects and use rev-list, but WITHOUT any filtering.
 200# This models previously omitted objects that we did not receive.
 201
 202test_expect_success 'rev-list W/ --missing=print' '
 203        git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
 204                | awk -f print_2.awk \
 205                | sort >expected &&
 206        for id in `cat expected | sed "s|..|&/|"`
 207        do
 208                rm r1/.git/objects/$id
 209        done &&
 210        git -C r1 rev-list --quiet HEAD --missing=print --objects \
 211                | awk -f print_1.awk \
 212                | sed "s/?//" \
 213                | sort >observed &&
 214        test_cmp observed expected
 215'
 216
 217test_expect_success 'rev-list W/O --missing fails' '
 218        test_must_fail git -C r1 rev-list --quiet --objects HEAD
 219'
 220
 221test_expect_success 'rev-list W/ missing=allow-any' '
 222        git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
 223'
 224
 225test_done