t / t8010-cat-file-filters.shon commit Merge branch 'jc/denoise-rm-to-resolve' (5e9d978)
   1#!/bin/sh
   2
   3test_description='git cat-file filters support'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup ' '
   7        echo "*.txt eol=crlf diff=txt" >.gitattributes &&
   8        echo "hello" | append_cr >world.txt &&
   9        git add .gitattributes world.txt &&
  10        test_tick &&
  11        git commit -m "Initial commit"
  12'
  13
  14has_cr () {
  15        tr '\015' Q <"$1" | grep Q >/dev/null
  16}
  17
  18test_expect_success 'no filters with `git show`' '
  19        git show HEAD:world.txt >actual &&
  20        ! has_cr actual
  21
  22'
  23
  24test_expect_success 'no filters with cat-file' '
  25        git cat-file blob HEAD:world.txt >actual &&
  26        ! has_cr actual
  27'
  28
  29test_expect_success 'cat-file --filters converts to worktree version' '
  30        git cat-file --filters HEAD:world.txt >actual &&
  31        has_cr actual
  32'
  33
  34test_expect_success 'cat-file --filters --path=<path> works' '
  35        sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
  36        git cat-file --filters --path=world.txt $sha1 >actual &&
  37        has_cr actual
  38'
  39
  40test_expect_success 'cat-file --textconv --path=<path> works' '
  41        sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
  42        test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&
  43        git cat-file --textconv --path=hello.txt $sha1 >rot13 &&
  44        test uryyb = "$(cat rot13 | remove_cr)"
  45'
  46
  47test_expect_success '--path=<path> complains without --textconv/--filters' '
  48        sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
  49        test_must_fail git cat-file --path=hello.txt blob $sha1 >actual 2>err &&
  50        test_must_be_empty actual &&
  51        grep "path.*needs.*filters" err
  52'
  53
  54test_expect_success '--textconv/--filters complain without path' '
  55        test_must_fail git cat-file --textconv HEAD &&
  56        test_must_fail git cat-file --filters HEAD
  57'
  58
  59test_expect_success 'cat-file --textconv --batch works' '
  60        sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
  61        test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&
  62        printf "%s hello.txt\n%s hello\n" $sha1 $sha1 |
  63        git cat-file --textconv --batch >actual &&
  64        printf "%s blob 6\nuryyb\r\n\n%s blob 6\nhello\n\n" \
  65                $sha1 $sha1 >expect &&
  66        test_cmp expect actual
  67'
  68
  69test_done