t / t8007-cat-file-textconv.shon commit Merge branch 'jk/unpack-entry-fallback-to-another' (ee64e34)
   1#!/bin/sh
   2
   3test_description='git cat-file textconv support'
   4. ./test-lib.sh
   5
   6cat >helper <<'EOF'
   7#!/bin/sh
   8grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
   9sed 's/^bin: /converted: /' "$1"
  10EOF
  11chmod +x helper
  12
  13test_expect_success 'setup ' '
  14        echo "bin: test" >one.bin &&
  15        test_ln_s_add one.bin symlink.bin &&
  16        git add . &&
  17        GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
  18        echo "bin: test version 2" >one.bin &&
  19        GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
  20'
  21
  22cat >expected <<EOF
  23fatal: git cat-file --textconv: unable to run textconv on :one.bin
  24EOF
  25
  26test_expect_success 'no filter specified' '
  27        git cat-file --textconv :one.bin 2>result
  28        test_cmp expected result
  29'
  30
  31test_expect_success 'setup textconv filters' '
  32        echo "*.bin diff=test" >.gitattributes &&
  33        git config diff.test.textconv ./helper &&
  34        git config diff.test.cachetextconv false
  35'
  36
  37cat >expected <<EOF
  38bin: test version 2
  39EOF
  40
  41test_expect_success 'cat-file without --textconv' '
  42        git cat-file blob :one.bin >result &&
  43        test_cmp expected result
  44'
  45
  46cat >expected <<EOF
  47bin: test
  48EOF
  49
  50test_expect_success 'cat-file without --textconv on previous commit' '
  51        git cat-file -p HEAD^:one.bin >result &&
  52        test_cmp expected result
  53'
  54
  55cat >expected <<EOF
  56converted: test version 2
  57EOF
  58
  59test_expect_success 'cat-file --textconv on last commit' '
  60        git cat-file --textconv :one.bin >result &&
  61        test_cmp expected result
  62'
  63
  64cat >expected <<EOF
  65converted: test
  66EOF
  67
  68test_expect_success 'cat-file --textconv on previous commit' '
  69        git cat-file --textconv HEAD^:one.bin >result &&
  70        test_cmp expected result
  71'
  72
  73test_expect_success 'cat-file without --textconv (symlink)' '
  74        git cat-file blob :symlink.bin >result &&
  75        printf "%s" "one.bin" >expected
  76        test_cmp expected result
  77'
  78
  79
  80test_expect_success 'cat-file --textconv on index (symlink)' '
  81        ! git cat-file --textconv :symlink.bin 2>result &&
  82        cat >expected <<\EOF &&
  83fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
  84EOF
  85        test_cmp expected result
  86'
  87
  88test_expect_success 'cat-file --textconv on HEAD (symlink)' '
  89        ! git cat-file --textconv HEAD:symlink.bin 2>result &&
  90        cat >expected <<EOF &&
  91fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin
  92EOF
  93        test_cmp expected result
  94'
  95
  96test_done