blob: 7683515155497d9303f319b31c3a49fb6610706f [file] [log] [blame]
Axel Bonnet37d29e12010-06-07 17:23:38 +02001#!/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
Kirill Smelkov6517cf72010-09-29 15:35:22 +040012grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
Junio C Hamano7096b642012-06-12 09:49:59 -070013"$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
Axel Bonnet37d29e12010-06-07 17:23:38 +020014EOF
15chmod +x helper
16
17test_expect_success 'setup ' '
Junio C Hamano55e7c0a2011-10-28 09:36:55 -070018 echo "bin: test number 0" >zero.bin &&
Kirill Smelkov6517cf72010-09-29 15:35:22 +040019 echo "bin: test 1" >one.bin &&
20 echo "bin: test number 2" >two.bin &&
Johannes Sixt889c6f02013-06-07 22:53:28 +020021 test_ln_s_add one.bin symlink.bin &&
Axel Bonnet37d29e12010-06-07 17:23:38 +020022 git add . &&
23 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
Kirill Smelkov6517cf72010-09-29 15:35:22 +040024 echo "bin: test 1 version 2" >one.bin &&
25 echo "bin: test number 2 version 2" >>two.bin &&
Johannes Sixt889c6f02013-06-07 22:53:28 +020026 rm -f symlink.bin &&
27 test_ln_s_add two.bin symlink.bin &&
Axel Bonnet37d29e12010-06-07 17:23:38 +020028 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
29'
30
31cat >expected <<EOF
Kirill Smelkov6517cf72010-09-29 15:35:22 +040032(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
Axel Bonnet37d29e12010-06-07 17:23:38 +020033EOF
34
35test_expect_success 'no filter specified' '
36 git blame one.bin >blame &&
37 find_blame Number2 <blame >result &&
38 test_cmp expected result
39'
40
41test_expect_success 'setup textconv filters' '
42 echo "*.bin diff=test" >.gitattributes &&
Junio C Hamano55e7c0a2011-10-28 09:36:55 -070043 echo "zero.bin eol=crlf" >>.gitattributes &&
Axel Bonnet37d29e12010-06-07 17:23:38 +020044 git config diff.test.textconv ./helper &&
45 git config diff.test.cachetextconv false
46'
47
48test_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
54cat >expected <<EOF
55(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
56EOF
57
58test_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
64cat >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
67EOF
68
69test_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 Hamano55e7c0a2011-10-28 09:36:55 -070075test_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 Smelkovb1b14ec2010-12-18 17:54:11 +030084test_expect_success 'setup +cachetextconv' '
85 git config diff.test.cachetextconv true
86'
87
88cat >expected_one <<EOF
89(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
90EOF
91
Kirill Smelkov9ec09b02010-12-18 17:54:12 +030092test_expect_success 'blame --textconv works with textconvcache' '
Kirill Smelkovb1b14ec2010-12-18 17:54:11 +030093 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
101test_expect_success 'setup -cachetextconv' '
102 git config diff.test.cachetextconv false
103'
104
Axel Bonnet37d29e12010-06-07 17:23:38 +0200105test_expect_success 'make a new commit' '
Kirill Smelkov6517cf72010-09-29 15:35:22 +0400106 echo "bin: test number 2 version 3" >>two.bin &&
Axel Bonnet37d29e12010-06-07 17:23:38 +0200107 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
108'
109
110test_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 Smelkovab3b7b92010-09-29 15:35:23 +0400116cat >expected <<EOF
117(Number2 2010-01-01 20:00:00 +0000 1) two.bin
118EOF
119
120test_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 Smelkov90064712010-09-29 15:35:24 +0400126test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400127 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 Sixt889c6f02013-06-07 22:53:28 +0200134test_expect_success 'make another new commit' '
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400135 cat >three.bin <<\EOF &&
136bin: test number 2
137bin: test number 2 version 2
138bin: test number 2 version 3
139bin: test number 3
140EOF
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 Sixt889c6f02013-06-07 22:53:28 +0200145test_expect_success 'blame on last commit (-C -C, symlink)' '
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400146 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
153EOF
154 test_cmp expected result
155'
156
Axel Bonnet37d29e12010-06-07 17:23:38 +0200157test_done