Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git blame textconv support' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | find_blame() { |
| 7 | sed -e 's/^[^(]*//' |
| 8 | } |
| 9 | |
| 10 | cat >helper <<'EOF' |
| 11 | #!/bin/sh |
Kirill Smelkov | 6517cf7 | 2010-09-29 15:35:22 +0400 | [diff] [blame] | 12 | grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } |
Junio C Hamano | 7096b64 | 2012-06-12 09:49:59 -0700 | [diff] [blame] | 13 | "$PERL_PATH" -p -e 's/^bin: /converted: /' "$1" |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 14 | EOF |
| 15 | chmod +x helper |
| 16 | |
| 17 | test_expect_success 'setup ' ' |
Junio C Hamano | 55e7c0a | 2011-10-28 09:36:55 -0700 | [diff] [blame] | 18 | echo "bin: test number 0" >zero.bin && |
Kirill Smelkov | 6517cf7 | 2010-09-29 15:35:22 +0400 | [diff] [blame] | 19 | echo "bin: test 1" >one.bin && |
| 20 | echo "bin: test number 2" >two.bin && |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 21 | test_ln_s_add one.bin symlink.bin && |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 22 | git add . && |
| 23 | GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" && |
Kirill Smelkov | 6517cf7 | 2010-09-29 15:35:22 +0400 | [diff] [blame] | 24 | echo "bin: test 1 version 2" >one.bin && |
| 25 | echo "bin: test number 2 version 2" >>two.bin && |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 26 | rm -f symlink.bin && |
| 27 | test_ln_s_add two.bin symlink.bin && |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 28 | GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" |
| 29 | ' |
| 30 | |
| 31 | cat >expected <<EOF |
Kirill Smelkov | 6517cf7 | 2010-09-29 15:35:22 +0400 | [diff] [blame] | 32 | (Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2 |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 33 | EOF |
| 34 | |
| 35 | test_expect_success 'no filter specified' ' |
| 36 | git blame one.bin >blame && |
| 37 | find_blame Number2 <blame >result && |
| 38 | test_cmp expected result |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'setup textconv filters' ' |
| 42 | echo "*.bin diff=test" >.gitattributes && |
Junio C Hamano | 55e7c0a | 2011-10-28 09:36:55 -0700 | [diff] [blame] | 43 | echo "zero.bin eol=crlf" >>.gitattributes && |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 44 | git config diff.test.textconv ./helper && |
| 45 | git config diff.test.cachetextconv false |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'blame with --no-textconv' ' |
| 49 | git blame --no-textconv one.bin >blame && |
| 50 | find_blame <blame> result && |
| 51 | test_cmp expected result |
| 52 | ' |
| 53 | |
| 54 | cat >expected <<EOF |
| 55 | (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2 |
| 56 | EOF |
| 57 | |
| 58 | test_expect_success 'basic blame on last commit' ' |
| 59 | git blame one.bin >blame && |
| 60 | find_blame <blame >result && |
| 61 | test_cmp expected result |
| 62 | ' |
| 63 | |
| 64 | cat >expected <<EOF |
| 65 | (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2 |
| 66 | (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2 |
| 67 | EOF |
| 68 | |
| 69 | test_expect_success 'blame --textconv going through revisions' ' |
| 70 | git blame --textconv two.bin >blame && |
| 71 | find_blame <blame >result && |
| 72 | test_cmp expected result |
| 73 | ' |
| 74 | |
Junio C Hamano | 55e7c0a | 2011-10-28 09:36:55 -0700 | [diff] [blame] | 75 | test_expect_success 'blame --textconv with local changes' ' |
| 76 | test_when_finished "git checkout zero.bin" && |
| 77 | printf "bin: updated number 0\015" >zero.bin && |
| 78 | git blame --textconv zero.bin >blame && |
| 79 | expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" && |
| 80 | expect="$expect converted: updated number 0" && |
| 81 | expr "$(find_blame <blame)" : "^$expect" |
| 82 | ' |
| 83 | |
Kirill Smelkov | b1b14ec | 2010-12-18 17:54:11 +0300 | [diff] [blame] | 84 | test_expect_success 'setup +cachetextconv' ' |
| 85 | git config diff.test.cachetextconv true |
| 86 | ' |
| 87 | |
| 88 | cat >expected_one <<EOF |
| 89 | (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2 |
| 90 | EOF |
| 91 | |
Kirill Smelkov | 9ec09b0 | 2010-12-18 17:54:12 +0300 | [diff] [blame] | 92 | test_expect_success 'blame --textconv works with textconvcache' ' |
Kirill Smelkov | b1b14ec | 2010-12-18 17:54:11 +0300 | [diff] [blame] | 93 | git blame --textconv two.bin >blame && |
| 94 | find_blame <blame >result && |
| 95 | test_cmp expected result && |
| 96 | git blame --textconv one.bin >blame && |
| 97 | find_blame <blame >result && |
| 98 | test_cmp expected_one result |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'setup -cachetextconv' ' |
| 102 | git config diff.test.cachetextconv false |
| 103 | ' |
| 104 | |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 105 | test_expect_success 'make a new commit' ' |
Kirill Smelkov | 6517cf7 | 2010-09-29 15:35:22 +0400 | [diff] [blame] | 106 | echo "bin: test number 2 version 3" >>two.bin && |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 107 | GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00" |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'blame from previous revision' ' |
| 111 | git blame HEAD^ two.bin >blame && |
| 112 | find_blame <blame >result && |
| 113 | test_cmp expected result |
| 114 | ' |
| 115 | |
Kirill Smelkov | ab3b7b9 | 2010-09-29 15:35:23 +0400 | [diff] [blame] | 116 | cat >expected <<EOF |
| 117 | (Number2 2010-01-01 20:00:00 +0000 1) two.bin |
| 118 | EOF |
| 119 | |
| 120 | test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' ' |
| 121 | git blame --no-textconv symlink.bin >blame && |
| 122 | find_blame <blame >result && |
| 123 | test_cmp expected result |
| 124 | ' |
| 125 | |
Kirill Smelkov | 9006471 | 2010-09-29 15:35:24 +0400 | [diff] [blame] | 126 | test_expect_success SYMLINKS 'blame --textconv (on symlink)' ' |
Kirill Smelkov | ab3b7b9 | 2010-09-29 15:35:23 +0400 | [diff] [blame] | 127 | git blame --textconv symlink.bin >blame && |
| 128 | find_blame <blame >result && |
| 129 | test_cmp expected result |
| 130 | ' |
| 131 | |
| 132 | # cp two.bin three.bin and make small tweak |
| 133 | # (this will direct blame -C -C three.bin to consider two.bin and symlink.bin) |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 134 | test_expect_success 'make another new commit' ' |
Kirill Smelkov | ab3b7b9 | 2010-09-29 15:35:23 +0400 | [diff] [blame] | 135 | cat >three.bin <<\EOF && |
| 136 | bin: test number 2 |
| 137 | bin: test number 2 version 2 |
| 138 | bin: test number 2 version 3 |
| 139 | bin: test number 3 |
| 140 | EOF |
| 141 | git add three.bin && |
| 142 | GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00" |
| 143 | ' |
| 144 | |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 145 | test_expect_success 'blame on last commit (-C -C, symlink)' ' |
Kirill Smelkov | ab3b7b9 | 2010-09-29 15:35:23 +0400 | [diff] [blame] | 146 | git blame -C -C three.bin >blame && |
| 147 | find_blame <blame >result && |
| 148 | cat >expected <<\EOF && |
| 149 | (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2 |
| 150 | (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2 |
| 151 | (Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3 |
| 152 | (Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3 |
| 153 | EOF |
| 154 | test_cmp expected result |
| 155 | ' |
| 156 | |
Axel Bonnet | 37d29e1 | 2010-06-07 17:23:38 +0200 | [diff] [blame] | 157 | test_done |