1#!/bin/sh
2
3test_description='git blame corner cases'
4. ./test-lib.sh
5
6pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
7
8test_expect_success setup '
9
10 echo A A A A A >one &&
11 echo B B B B B >two &&
12 echo C C C C C >tres &&
13 echo ABC >mouse &&
14 git add one two tres mouse &&
15 test_tick &&
16 GIT_AUTHOR_NAME=Initial git commit -m Initial &&
17
18 cat one >uno &&
19 mv two dos &&
20 cat one >>tres &&
21 echo DEF >>mouse
22 git add uno dos tres mouse &&
23 test_tick &&
24 GIT_AUTHOR_NAME=Second git commit -a -m Second &&
25
26 echo GHIJK >>mouse &&
27 git add mouse &&
28 test_tick &&
29 GIT_AUTHOR_NAME=Third git commit -m Third &&
30
31 cat mouse >cow &&
32 git add cow &&
33 test_tick &&
34 GIT_AUTHOR_NAME=Fourth git commit -m Fourth &&
35
36 {
37 echo ABC
38 echo DEF
39 echo XXXX
40 echo GHIJK
41 } >cow &&
42 git add cow &&
43 test_tick &&
44 GIT_AUTHOR_NAME=Fifth git commit -m Fifth
45'
46
47test_expect_success 'straight copy without -C' '
48
49 git blame uno | grep Second
50
51'
52
53test_expect_success 'straight move without -C' '
54
55 git blame dos | grep Initial
56
57'
58
59test_expect_success 'straight copy with -C' '
60
61 git blame -C1 uno | grep Second
62
63'
64
65test_expect_success 'straight move with -C' '
66
67 git blame -C1 dos | grep Initial
68
69'
70
71test_expect_success 'straight copy with -C -C' '
72
73 git blame -C -C1 uno | grep Initial
74
75'
76
77test_expect_success 'straight move with -C -C' '
78
79 git blame -C -C1 dos | grep Initial
80
81'
82
83test_expect_success 'append without -C' '
84
85 git blame -L2 tres | grep Second
86
87'
88
89test_expect_success 'append with -C' '
90
91 git blame -L2 -C1 tres | grep Second
92
93'
94
95test_expect_success 'append with -C -C' '
96
97 git blame -L2 -C -C1 tres | grep Second
98
99'
100
101test_expect_success 'append with -C -C -C' '
102
103 git blame -L2 -C -C -C1 tres | grep Initial
104
105'
106
107test_expect_success 'blame wholesale copy' '
108
109 git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current &&
110 {
111 echo mouse-Initial
112 echo mouse-Second
113 echo mouse-Third
114 } >expected &&
115 test_cmp expected current
116
117'
118
119test_expect_success 'blame wholesale copy and more' '
120
121 git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current &&
122 {
123 echo mouse-Initial
124 echo mouse-Second
125 echo cow-Fifth
126 echo mouse-Third
127 } >expected &&
128 test_cmp expected current
129
130'
131
132test_expect_success 'blame path that used to be a directory' '
133 mkdir path &&
134 echo A A A A A >path/file &&
135 echo B B B B B >path/elif &&
136 git add path &&
137 test_tick &&
138 git commit -m "path was a directory" &&
139 rm -fr path &&
140 echo A A A A A >path &&
141 git add path &&
142 test_tick &&
143 git commit -m "path is a regular file" &&
144 git blame HEAD^.. -- path
145'
146
147test_expect_success 'blame to a commit with no author name' '
148 TREE=`git rev-parse HEAD:`
149 cat >badcommit <<EOF
150tree $TREE
151author <noname> 1234567890 +0000
152committer David Reiss <dreiss@facebook.com> 1234567890 +0000
153
154some message
155EOF
156 COMMIT=`git hash-object -t commit -w badcommit`
157 git --no-pager blame $COMMIT -- uno >/dev/null
158'
159
160test_done