2007-05-06 09:36:19 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git blame corner cases'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
echo A A A A A >one &&
|
|
|
|
echo B B B B B >two &&
|
|
|
|
echo C C C C C >tres &&
|
|
|
|
echo ABC >mouse &&
|
2010-03-13 13:25:12 +03:00
|
|
|
for i in 1 2 3 4 5 6 7 8 9
|
|
|
|
do
|
|
|
|
echo $i
|
|
|
|
done >nine_lines &&
|
|
|
|
for i in 1 2 3 4 5 6 7 8 9 a
|
|
|
|
do
|
|
|
|
echo $i
|
|
|
|
done >ten_lines &&
|
|
|
|
git add one two tres mouse nine_lines ten_lines &&
|
2007-05-06 09:36:19 +04:00
|
|
|
test_tick &&
|
|
|
|
GIT_AUTHOR_NAME=Initial git commit -m Initial &&
|
|
|
|
|
|
|
|
cat one >uno &&
|
|
|
|
mv two dos &&
|
|
|
|
cat one >>tres &&
|
2015-03-20 13:07:15 +03:00
|
|
|
echo DEF >>mouse &&
|
2007-05-06 09:36:19 +04:00
|
|
|
git add uno dos tres mouse &&
|
|
|
|
test_tick &&
|
|
|
|
GIT_AUTHOR_NAME=Second git commit -a -m Second &&
|
|
|
|
|
|
|
|
echo GHIJK >>mouse &&
|
|
|
|
git add mouse &&
|
|
|
|
test_tick &&
|
|
|
|
GIT_AUTHOR_NAME=Third git commit -m Third &&
|
|
|
|
|
|
|
|
cat mouse >cow &&
|
|
|
|
git add cow &&
|
|
|
|
test_tick &&
|
|
|
|
GIT_AUTHOR_NAME=Fourth git commit -m Fourth &&
|
|
|
|
|
2016-07-16 02:23:46 +03:00
|
|
|
cat >cow <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
XXXX
|
|
|
|
GHIJK
|
|
|
|
EOF
|
2007-05-06 09:36:19 +04:00
|
|
|
git add cow &&
|
|
|
|
test_tick &&
|
|
|
|
GIT_AUTHOR_NAME=Fifth git commit -m Fifth
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'straight copy without -C' '
|
|
|
|
|
|
|
|
git blame uno | grep Second
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'straight move without -C' '
|
|
|
|
|
|
|
|
git blame dos | grep Initial
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'straight copy with -C' '
|
|
|
|
|
|
|
|
git blame -C1 uno | grep Second
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'straight move with -C' '
|
|
|
|
|
|
|
|
git blame -C1 dos | grep Initial
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'straight copy with -C -C' '
|
|
|
|
|
|
|
|
git blame -C -C1 uno | grep Initial
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'straight move with -C -C' '
|
|
|
|
|
|
|
|
git blame -C -C1 dos | grep Initial
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'append without -C' '
|
|
|
|
|
|
|
|
git blame -L2 tres | grep Second
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'append with -C' '
|
|
|
|
|
|
|
|
git blame -L2 -C1 tres | grep Second
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'append with -C -C' '
|
|
|
|
|
|
|
|
git blame -L2 -C -C1 tres | grep Second
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'append with -C -C -C' '
|
|
|
|
|
|
|
|
git blame -L2 -C -C -C1 tres | grep Initial
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame wholesale copy' '
|
|
|
|
|
|
|
|
git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current &&
|
2016-07-16 02:23:46 +03:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
mouse-Initial
|
|
|
|
mouse-Second
|
|
|
|
mouse-Third
|
|
|
|
EOF
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected current
|
2007-05-06 09:36:19 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame wholesale copy and more' '
|
|
|
|
|
|
|
|
git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current &&
|
2016-07-16 02:23:46 +03:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
mouse-Initial
|
|
|
|
mouse-Second
|
|
|
|
cow-Fifth
|
|
|
|
mouse-Third
|
|
|
|
EOF
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected current
|
2007-05-06 09:36:19 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2016-07-16 02:23:45 +03:00
|
|
|
test_expect_success 'blame wholesale copy and more in the index' '
|
|
|
|
|
|
|
|
cat >horse <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
XXXX
|
|
|
|
YYYY
|
|
|
|
GHIJK
|
|
|
|
EOF
|
|
|
|
git add horse &&
|
|
|
|
test_when_finished "git rm -f horse" &&
|
|
|
|
git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current &&
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
mouse-Initial
|
|
|
|
mouse-Second
|
|
|
|
cow-Fifth
|
|
|
|
horse-Not
|
|
|
|
mouse-Third
|
|
|
|
EOF
|
|
|
|
test_cmp expected current
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame during cherry-pick with file rename conflict' '
|
|
|
|
|
|
|
|
test_when_finished "git reset --hard && git checkout master" &&
|
|
|
|
git checkout HEAD~3 &&
|
|
|
|
echo MOUSE >> mouse &&
|
|
|
|
git mv mouse rodent &&
|
|
|
|
git add rodent &&
|
|
|
|
GIT_AUTHOR_NAME=Rodent git commit -m "rodent" &&
|
|
|
|
git checkout --detach master &&
|
|
|
|
(git cherry-pick HEAD@{1} || test $? -eq 1) &&
|
|
|
|
git show HEAD@{1}:rodent > rodent &&
|
|
|
|
git add rodent &&
|
|
|
|
git blame -f -C -C1 rodent | sed -e "$pick_fc" >current &&
|
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
mouse-Initial
|
|
|
|
mouse-Second
|
|
|
|
rodent-Not
|
|
|
|
EOF
|
|
|
|
test_cmp expected current
|
|
|
|
'
|
|
|
|
|
2009-06-03 11:43:22 +04:00
|
|
|
test_expect_success 'blame path that used to be a directory' '
|
|
|
|
mkdir path &&
|
|
|
|
echo A A A A A >path/file &&
|
|
|
|
echo B B B B B >path/elif &&
|
|
|
|
git add path &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "path was a directory" &&
|
|
|
|
rm -fr path &&
|
|
|
|
echo A A A A A >path &&
|
|
|
|
git add path &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "path is a regular file" &&
|
|
|
|
git blame HEAD^.. -- path
|
|
|
|
'
|
|
|
|
|
2009-12-22 21:51:41 +03:00
|
|
|
test_expect_success 'blame to a commit with no author name' '
|
2016-01-08 14:06:26 +03:00
|
|
|
TREE=$(git rev-parse HEAD:) &&
|
2015-03-20 13:07:15 +03:00
|
|
|
cat >badcommit <<EOF &&
|
2009-12-22 21:51:41 +03:00
|
|
|
tree $TREE
|
|
|
|
author <noname> 1234567890 +0000
|
|
|
|
committer David Reiss <dreiss@facebook.com> 1234567890 +0000
|
|
|
|
|
|
|
|
some message
|
|
|
|
EOF
|
2016-01-08 14:06:26 +03:00
|
|
|
COMMIT=$(git hash-object -t commit -w badcommit) &&
|
2009-12-22 21:51:41 +03:00
|
|
|
git --no-pager blame $COMMIT -- uno >/dev/null
|
|
|
|
'
|
|
|
|
|
2010-02-09 06:48:13 +03:00
|
|
|
test_expect_success 'blame -L with invalid start' '
|
2010-02-09 21:06:33 +03:00
|
|
|
test_must_fail git blame -L5 tres 2>errors &&
|
2016-09-15 17:58:58 +03:00
|
|
|
test_i18ngrep "has only 2 lines" errors
|
2010-02-09 06:48:13 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame -L with invalid end' '
|
2018-06-15 09:29:27 +03:00
|
|
|
git blame -L1,5 tres >out &&
|
|
|
|
test_line_count = 2 out
|
2010-02-09 06:48:13 +03:00
|
|
|
'
|
|
|
|
|
2013-03-28 20:47:30 +04:00
|
|
|
test_expect_success 'blame parses <end> part of -L' '
|
|
|
|
git blame -L1,1 tres >out &&
|
2018-06-15 09:29:27 +03:00
|
|
|
test_line_count = 1 out
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame -Ln,-(n+1)' '
|
|
|
|
git blame -L3,-4 nine_lines >out &&
|
|
|
|
test_line_count = 3 out
|
2013-03-28 20:47:30 +04:00
|
|
|
'
|
|
|
|
|
2010-03-13 13:25:12 +03:00
|
|
|
test_expect_success 'indent of line numbers, nine lines' '
|
|
|
|
git blame nine_lines >actual &&
|
|
|
|
test $(grep -c " " actual) = 0
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'indent of line numbers, ten lines' '
|
|
|
|
git blame ten_lines >actual &&
|
|
|
|
test $(grep -c " " actual) = 9
|
|
|
|
'
|
|
|
|
|
2015-05-03 19:38:01 +03:00
|
|
|
test_expect_success 'setup file with CRLF newlines' '
|
2014-04-27 03:10:40 +04:00
|
|
|
git config core.autocrlf false &&
|
2015-05-03 19:38:01 +03:00
|
|
|
printf "testcase\n" >crlffile &&
|
2014-04-27 03:10:40 +04:00
|
|
|
git add crlffile &&
|
|
|
|
git commit -m testcase &&
|
2015-05-03 19:38:01 +03:00
|
|
|
printf "testcase\r\n" >crlffile
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame file with CRLF core.autocrlf true' '
|
|
|
|
git config core.autocrlf true &&
|
|
|
|
git blame crlffile >actual &&
|
|
|
|
grep "A U Thor" actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame file with CRLF attributes text' '
|
|
|
|
git config core.autocrlf false &&
|
|
|
|
echo "crlffile text" >.gitattributes &&
|
|
|
|
git blame crlffile >actual &&
|
2014-04-27 03:10:40 +04:00
|
|
|
grep "A U Thor" actual
|
|
|
|
'
|
|
|
|
|
2016-04-05 22:23:54 +03:00
|
|
|
test_expect_success 'blame file with CRLF core.autocrlf=true' '
|
|
|
|
git config core.autocrlf false &&
|
|
|
|
printf "testcase\r\n" >crlfinrepo &&
|
|
|
|
>.gitattributes &&
|
|
|
|
git add crlfinrepo &&
|
|
|
|
git commit -m "add crlfinrepo" &&
|
|
|
|
git config core.autocrlf true &&
|
|
|
|
mv crlfinrepo tmp &&
|
|
|
|
git checkout crlfinrepo &&
|
|
|
|
rm tmp &&
|
|
|
|
git blame crlfinrepo >actual &&
|
|
|
|
grep "A U Thor" actual
|
|
|
|
'
|
|
|
|
|
2019-06-20 19:38:20 +03:00
|
|
|
# Tests the splitting and merging of blame entries in blame_coalesce().
|
|
|
|
# The output of blame is the same, regardless of whether blame_coalesce() runs
|
|
|
|
# or not, so we'd likely only notice a problem if blame crashes or assigned
|
|
|
|
# blame to the "splitting" commit ('SPLIT' below).
|
|
|
|
test_expect_success 'blame coalesce' '
|
|
|
|
cat >giraffe <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
EOF
|
|
|
|
git add giraffe &&
|
|
|
|
git commit -m "original file" &&
|
|
|
|
oid=$(git rev-parse HEAD) &&
|
|
|
|
|
|
|
|
cat >giraffe <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
SPLIT
|
|
|
|
DEF
|
|
|
|
EOF
|
|
|
|
git add giraffe &&
|
|
|
|
git commit -m "interior SPLIT line" &&
|
|
|
|
|
|
|
|
cat >giraffe <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
EOF
|
|
|
|
git add giraffe &&
|
|
|
|
git commit -m "same contents as original" &&
|
|
|
|
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
$oid 1) ABC
|
|
|
|
$oid 2) DEF
|
|
|
|
EOF
|
|
|
|
git -c core.abbrev=40 blame -s giraffe >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2007-05-06 09:36:19 +04:00
|
|
|
test_done
|