1#!/bin/sh
2
3test_description='git blame textconv support'
4. ./test-lib.sh
5
6find_blame() {
7 sed -e 's/^[^(]*//'
8}
9
10cat >helper <<'EOF'
11#!/bin/sh
12grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
13sed 's/^bin: /converted: /' "$1"
14EOF
15chmod +x helper
16
17test_expect_success 'setup ' '
18 echo "bin: test 1" >one.bin &&
19 echo "bin: test number 2" >two.bin &&
20 git add . &&
21 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
22 echo "bin: test 1 version 2" >one.bin &&
23 echo "bin: test number 2 version 2" >>two.bin &&
24 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
25'
26
27cat >expected <<EOF
28(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
29EOF
30
31test_expect_success 'no filter specified' '
32 git blame one.bin >blame &&
33 find_blame Number2 <blame >result &&
34 test_cmp expected result
35'
36
37test_expect_success 'setup textconv filters' '
38 echo "*.bin diff=test" >.gitattributes &&
39 git config diff.test.textconv ./helper &&
40 git config diff.test.cachetextconv false
41'
42
43test_expect_success 'blame with --no-textconv' '
44 git blame --no-textconv one.bin >blame &&
45 find_blame <blame> result &&
46 test_cmp expected result
47'
48
49cat >expected <<EOF
50(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
51EOF
52
53test_expect_success 'basic blame on last commit' '
54 git blame one.bin >blame &&
55 find_blame <blame >result &&
56 test_cmp expected result
57'
58
59cat >expected <<EOF
60(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
61(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
62EOF
63
64test_expect_success 'blame --textconv going through revisions' '
65 git blame --textconv two.bin >blame &&
66 find_blame <blame >result &&
67 test_cmp expected result
68'
69
70test_expect_success 'make a new commit' '
71 echo "bin: test number 2 version 3" >>two.bin &&
72 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
73'
74
75test_expect_success 'blame from previous revision' '
76 git blame HEAD^ two.bin >blame &&
77 find_blame <blame >result &&
78 test_cmp expected result
79'
80
81test_done