blob: bf6caa4dc3d42230757526dd215ab777f77ae369 [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 &&
Kirill Smelkovab3b7b92010-09-29 15:35:23 +040021 if test_have_prereq SYMLINKS; then
22 ln -s one.bin symlink.bin
23 fi &&
Axel Bonnet37d29e12010-06-07 17:23:38 +020024 git add . &&
25 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
Kirill Smelkov6517cf72010-09-29 15:35:22 +040026 echo "bin: test 1 version 2" >one.bin &&
27 echo "bin: test number 2 version 2" >>two.bin &&
Kirill Smelkovab3b7b92010-09-29 15:35:23 +040028 if test_have_prereq SYMLINKS; then
Ben Waltonc3786c82011-03-20 21:12:26 -040029 rm symlink.bin &&
30 ln -s two.bin symlink.bin
Kirill Smelkovab3b7b92010-09-29 15:35:23 +040031 fi &&
Axel Bonnet37d29e12010-06-07 17:23:38 +020032 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
33'
34
35cat >expected <<EOF
Kirill Smelkov6517cf72010-09-29 15:35:22 +040036(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
Axel Bonnet37d29e12010-06-07 17:23:38 +020037EOF
38
39test_expect_success 'no filter specified' '
40 git blame one.bin >blame &&
41 find_blame Number2 <blame >result &&
42 test_cmp expected result
43'
44
45test_expect_success 'setup textconv filters' '
46 echo "*.bin diff=test" >.gitattributes &&
Junio C Hamano55e7c0a2011-10-28 09:36:55 -070047 echo "zero.bin eol=crlf" >>.gitattributes &&
Axel Bonnet37d29e12010-06-07 17:23:38 +020048 git config diff.test.textconv ./helper &&
49 git config diff.test.cachetextconv false
50'
51
52test_expect_success 'blame with --no-textconv' '
53 git blame --no-textconv one.bin >blame &&
54 find_blame <blame> result &&
55 test_cmp expected result
56'
57
58cat >expected <<EOF
59(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
60EOF
61
62test_expect_success 'basic blame on last commit' '
63 git blame one.bin >blame &&
64 find_blame <blame >result &&
65 test_cmp expected result
66'
67
68cat >expected <<EOF
69(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
70(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
71EOF
72
73test_expect_success 'blame --textconv going through revisions' '
74 git blame --textconv two.bin >blame &&
75 find_blame <blame >result &&
76 test_cmp expected result
77'
78
Junio C Hamano55e7c0a2011-10-28 09:36:55 -070079test_expect_success 'blame --textconv with local changes' '
80 test_when_finished "git checkout zero.bin" &&
81 printf "bin: updated number 0\015" >zero.bin &&
82 git blame --textconv zero.bin >blame &&
83 expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" &&
84 expect="$expect converted: updated number 0" &&
85 expr "$(find_blame <blame)" : "^$expect"
86'
87
Kirill Smelkovb1b14ec2010-12-18 17:54:11 +030088test_expect_success 'setup +cachetextconv' '
89 git config diff.test.cachetextconv true
90'
91
92cat >expected_one <<EOF
93(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
94EOF
95
Kirill Smelkov9ec09b02010-12-18 17:54:12 +030096test_expect_success 'blame --textconv works with textconvcache' '
Kirill Smelkovb1b14ec2010-12-18 17:54:11 +030097 git blame --textconv two.bin >blame &&
98 find_blame <blame >result &&
99 test_cmp expected result &&
100 git blame --textconv one.bin >blame &&
101 find_blame <blame >result &&
102 test_cmp expected_one result
103'
104
105test_expect_success 'setup -cachetextconv' '
106 git config diff.test.cachetextconv false
107'
108
Axel Bonnet37d29e12010-06-07 17:23:38 +0200109test_expect_success 'make a new commit' '
Kirill Smelkov6517cf72010-09-29 15:35:22 +0400110 echo "bin: test number 2 version 3" >>two.bin &&
Axel Bonnet37d29e12010-06-07 17:23:38 +0200111 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
112'
113
114test_expect_success 'blame from previous revision' '
115 git blame HEAD^ two.bin >blame &&
116 find_blame <blame >result &&
117 test_cmp expected result
118'
119
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400120cat >expected <<EOF
121(Number2 2010-01-01 20:00:00 +0000 1) two.bin
122EOF
123
124test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
125 git blame --no-textconv symlink.bin >blame &&
126 find_blame <blame >result &&
127 test_cmp expected result
128'
129
Kirill Smelkov90064712010-09-29 15:35:24 +0400130test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400131 git blame --textconv symlink.bin >blame &&
132 find_blame <blame >result &&
133 test_cmp expected result
134'
135
136# cp two.bin three.bin and make small tweak
137# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
138test_expect_success SYMLINKS 'make another new commit' '
139 cat >three.bin <<\EOF &&
140bin: test number 2
141bin: test number 2 version 2
142bin: test number 2 version 3
143bin: test number 3
144EOF
145 git add three.bin &&
146 GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
147'
148
Kirill Smelkov90064712010-09-29 15:35:24 +0400149test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' '
Kirill Smelkovab3b7b92010-09-29 15:35:23 +0400150 git blame -C -C three.bin >blame &&
151 find_blame <blame >result &&
152 cat >expected <<\EOF &&
153(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
154(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
155(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
156(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
157EOF
158 test_cmp expected result
159'
160
Axel Bonnet37d29e12010-06-07 17:23:38 +0200161test_done