| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git cat-file textconv support' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | cat >helper <<'EOF' |
| 8 | #!/bin/sh |
| 9 | grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } |
| 10 | sed 's/^bin: /converted: /' "$1" |
| 11 | EOF |
| 12 | chmod +x helper |
| 13 | |
| 14 | test_expect_success 'setup ' ' |
| 15 | echo "bin: test" >one.bin && |
| 16 | test_ln_s_add one.bin symlink.bin && |
| 17 | git add . && |
| 18 | GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" && |
| 19 | echo "bin: test version 2" >one.bin && |
| 20 | GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" |
| 21 | ' |
| 22 | |
| 23 | test_expect_success 'usage: <bad rev>' ' |
| 24 | cat >expect <<-\EOF && |
| 25 | fatal: Not a valid object name HEAD2 |
| 26 | EOF |
| 27 | test_must_fail git cat-file --textconv HEAD2 2>actual && |
| 28 | test_cmp expect actual |
| 29 | ' |
| 30 | |
| 31 | test_expect_success 'usage: <bad rev>:<bad path>' ' |
| 32 | cat >expect <<-\EOF && |
| 33 | fatal: invalid object name '\''HEAD2'\''. |
| 34 | EOF |
| 35 | test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual && |
| 36 | test_cmp expect actual |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'usage: <rev>:<bad path>' ' |
| 40 | cat >expect <<-\EOF && |
| 41 | fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\'' |
| 42 | EOF |
| 43 | test_must_fail git cat-file --textconv HEAD:two.bin 2>actual && |
| 44 | test_cmp expect actual |
| 45 | ' |
| 46 | |
| 47 | |
| 48 | test_expect_success 'usage: <rev> with no <path>' ' |
| 49 | cat >expect <<-\EOF && |
| 50 | fatal: <object>:<path> required, only <object> '\''HEAD'\'' given |
| 51 | EOF |
| 52 | test_must_fail git cat-file --textconv HEAD 2>actual && |
| 53 | test_cmp expect actual |
| 54 | ' |
| 55 | |
| 56 | |
| 57 | test_expect_success 'usage: <bad rev>:<good (in HEAD) path>' ' |
| 58 | cat >expect <<-\EOF && |
| 59 | fatal: invalid object name '\''HEAD2'\''. |
| 60 | EOF |
| 61 | test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual && |
| 62 | test_cmp expect actual |
| 63 | ' |
| 64 | |
| 65 | cat >expected <<EOF |
| 66 | bin: test version 2 |
| 67 | EOF |
| 68 | |
| 69 | test_expect_success 'no filter specified' ' |
| 70 | git cat-file --textconv :one.bin >result && |
| 71 | test_cmp expected result |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'setup textconv filters' ' |
| 75 | echo "*.bin diff=test" >.gitattributes && |
| 76 | git config diff.test.textconv ./helper && |
| 77 | git config diff.test.cachetextconv false |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'cat-file without --textconv' ' |
| 81 | git cat-file blob :one.bin >result && |
| 82 | test_cmp expected result |
| 83 | ' |
| 84 | |
| 85 | cat >expected <<EOF |
| 86 | bin: test |
| 87 | EOF |
| 88 | |
| 89 | test_expect_success 'cat-file without --textconv on previous commit' ' |
| 90 | git cat-file -p HEAD^:one.bin >result && |
| 91 | test_cmp expected result |
| 92 | ' |
| 93 | |
| 94 | cat >expected <<EOF |
| 95 | converted: test version 2 |
| 96 | EOF |
| 97 | |
| 98 | test_expect_success 'cat-file --textconv on last commit' ' |
| 99 | git cat-file --textconv :one.bin >result && |
| 100 | test_cmp expected result |
| 101 | ' |
| 102 | |
| 103 | cat >expected <<EOF |
| 104 | converted: test |
| 105 | EOF |
| 106 | |
| 107 | test_expect_success 'cat-file --textconv on previous commit' ' |
| 108 | git cat-file --textconv HEAD^:one.bin >result && |
| 109 | test_cmp expected result |
| 110 | ' |
| 111 | |
| 112 | test_expect_success 'cat-file without --textconv (symlink)' ' |
| 113 | printf "%s" "one.bin" >expected && |
| 114 | git cat-file blob :symlink.bin >result && |
| 115 | test_cmp expected result |
| 116 | ' |
| 117 | |
| 118 | |
| 119 | test_expect_success 'cat-file --textconv on index (symlink)' ' |
| 120 | git cat-file --textconv :symlink.bin >result && |
| 121 | test_cmp expected result |
| 122 | ' |
| 123 | |
| 124 | test_expect_success 'cat-file --textconv on HEAD (symlink)' ' |
| 125 | git cat-file --textconv HEAD:symlink.bin >result && |
| 126 | test_cmp expected result |
| 127 | ' |
| 128 | |
| 129 | test_done |