2007-05-06 13:36:19 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git blame corner cases'
|
2020-11-19 07:44:41 +08:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 07:44:19 +08:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2007-05-06 13:36:19 +08:00
|
|
|
. ./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 &&
|
2021-12-09 13:11:05 +08:00
|
|
|
test_write_lines 1 2 3 4 5 6 7 8 9 >nine_lines &&
|
|
|
|
test_write_lines 1 2 3 4 5 6 7 8 9 a >ten_lines &&
|
2010-03-13 18:25:12 +08:00
|
|
|
git add one two tres mouse nine_lines ten_lines &&
|
2007-05-06 13:36:19 +08:00
|
|
|
test_tick &&
|
|
|
|
GIT_AUTHOR_NAME=Initial git commit -m Initial &&
|
|
|
|
|
|
|
|
cat one >uno &&
|
|
|
|
mv two dos &&
|
|
|
|
cat one >>tres &&
|
2015-03-20 18:07:15 +08:00
|
|
|
echo DEF >>mouse &&
|
2007-05-06 13:36:19 +08: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 07:23:46 +08:00
|
|
|
cat >cow <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
XXXX
|
|
|
|
GHIJK
|
|
|
|
EOF
|
2007-05-06 13:36:19 +08: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 07:23:46 +08:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
mouse-Initial
|
|
|
|
mouse-Second
|
|
|
|
mouse-Third
|
|
|
|
EOF
|
2008-03-13 05:36:36 +08:00
|
|
|
test_cmp expected current
|
2007-05-06 13:36:19 +08:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame wholesale copy and more' '
|
|
|
|
|
|
|
|
git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current &&
|
2016-07-16 07:23:46 +08:00
|
|
|
cat >expected <<-\EOF &&
|
|
|
|
mouse-Initial
|
|
|
|
mouse-Second
|
|
|
|
cow-Fifth
|
|
|
|
mouse-Third
|
|
|
|
EOF
|
2008-03-13 05:36:36 +08:00
|
|
|
test_cmp expected current
|
2007-05-06 13:36:19 +08:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2016-07-16 07:23:45 +08: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' '
|
|
|
|
|
2020-11-19 07:44:41 +08:00
|
|
|
test_when_finished "git reset --hard && git checkout main" &&
|
2016-07-16 07:23:45 +08:00
|
|
|
git checkout HEAD~3 &&
|
|
|
|
echo MOUSE >> mouse &&
|
|
|
|
git mv mouse rodent &&
|
|
|
|
git add rodent &&
|
|
|
|
GIT_AUTHOR_NAME=Rodent git commit -m "rodent" &&
|
2020-11-19 07:44:41 +08:00
|
|
|
git checkout --detach main &&
|
2016-07-16 07:23:45 +08:00
|
|
|
(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 15:43:22 +08: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-23 02:51:41 +08:00
|
|
|
test_expect_success 'blame to a commit with no author name' '
|
2016-01-08 19:06:26 +08:00
|
|
|
TREE=$(git rev-parse HEAD:) &&
|
2015-03-20 18:07:15 +08:00
|
|
|
cat >badcommit <<EOF &&
|
2009-12-23 02:51:41 +08:00
|
|
|
tree $TREE
|
|
|
|
author <noname> 1234567890 +0000
|
|
|
|
committer David Reiss <dreiss@facebook.com> 1234567890 +0000
|
|
|
|
|
|
|
|
some message
|
|
|
|
EOF
|
2016-01-08 19:06:26 +08:00
|
|
|
COMMIT=$(git hash-object -t commit -w badcommit) &&
|
2009-12-23 02:51:41 +08:00
|
|
|
git --no-pager blame $COMMIT -- uno >/dev/null
|
|
|
|
'
|
|
|
|
|
2010-02-09 11:48:13 +08:00
|
|
|
test_expect_success 'blame -L with invalid start' '
|
2010-02-10 02:06:33 +08:00
|
|
|
test_must_fail git blame -L5 tres 2>errors &&
|
2016-09-15 22:58:58 +08:00
|
|
|
test_i18ngrep "has only 2 lines" errors
|
2010-02-09 11:48:13 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'blame -L with invalid end' '
|
2018-06-15 14:29:27 +08:00
|
|
|
git blame -L1,5 tres >out &&
|
|
|
|
test_line_count = 2 out
|
2010-02-09 11:48:13 +08:00
|
|
|
'
|
|
|
|
|
2013-03-29 00:47:30 +08:00
|
|
|
test_expect_success 'blame parses <end> part of -L' '
|
|
|
|
git blame -L1,1 tres >out &&
|
2018-06-15 14:29:27 +08: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-29 00:47:30 +08:00
|
|
|
'
|
|
|
|
|
2010-03-13 18:25:12 +08: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-04 00:38:01 +08:00
|
|
|
test_expect_success 'setup file with CRLF newlines' '
|
2014-04-27 07:10:40 +08:00
|
|
|
git config core.autocrlf false &&
|
2015-05-04 00:38:01 +08:00
|
|
|
printf "testcase\n" >crlffile &&
|
2014-04-27 07:10:40 +08:00
|
|
|
git add crlffile &&
|
|
|
|
git commit -m testcase &&
|
2015-05-04 00:38:01 +08: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 07:10:40 +08:00
|
|
|
grep "A U Thor" actual
|
|
|
|
'
|
|
|
|
|
2016-04-06 03:23:54 +08: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
|
|
|
|
'
|
|
|
|
|
2020-08-13 13:23:41 +08:00
|
|
|
test_expect_success 'setup coalesce tests' '
|
2019-06-21 00:38:20 +08:00
|
|
|
cat >giraffe <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
EOF
|
|
|
|
git add giraffe &&
|
|
|
|
git commit -m "original file" &&
|
2020-08-13 13:23:41 +08:00
|
|
|
orig=$(git rev-parse HEAD) &&
|
2019-06-21 00:38:20 +08:00
|
|
|
|
|
|
|
cat >giraffe <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
SPLIT
|
|
|
|
DEF
|
|
|
|
EOF
|
|
|
|
git add giraffe &&
|
|
|
|
git commit -m "interior SPLIT line" &&
|
2020-08-13 13:23:41 +08:00
|
|
|
split=$(git rev-parse HEAD) &&
|
2019-06-21 00:38:20 +08:00
|
|
|
|
|
|
|
cat >giraffe <<-\EOF &&
|
|
|
|
ABC
|
|
|
|
DEF
|
|
|
|
EOF
|
|
|
|
git add giraffe &&
|
|
|
|
git commit -m "same contents as original" &&
|
2020-08-13 13:23:41 +08:00
|
|
|
final=$(git rev-parse HEAD)
|
|
|
|
'
|
2019-06-21 00:38:20 +08:00
|
|
|
|
2020-08-13 13:23:41 +08:00
|
|
|
test_expect_success 'blame coalesce' '
|
2019-06-21 00:38:20 +08:00
|
|
|
cat >expect <<-EOF &&
|
2020-08-13 13:23:41 +08:00
|
|
|
$orig 1 1 2
|
|
|
|
$orig 2 2
|
2019-06-21 00:38:20 +08:00
|
|
|
EOF
|
2020-08-13 13:23:41 +08:00
|
|
|
git blame --porcelain $final giraffe >actual.raw &&
|
|
|
|
grep "^$orig" actual.raw >actual &&
|
2019-06-21 00:38:20 +08:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
blame: only coalesce lines that are adjacent in result
After blame has finished but before we produce any output, we coalesce
groups of lines that were adjacent in the original suspect (which may
have been split apart by lines in intermediate commits which went away).
However, this can cause incorrect output if the lines are not also
adjacent in the result. For instance, the case in t8003 has:
ABC
DEF
which becomes
ABC
SPLIT
DEF
Blaming only lines 1 and 3 in the result yields two blame groups (one
for each line) that were adjacent in the original. That's enough for us
to coalesce them into a single group, but that loses information: our
output routines assume they're adjacent in the result as well, and we
output:
<oid> 1) ABC
<oid> 2) SPLIT
This is nonsense for two reasons:
- we were asked about line 3, not line 2; we should not output the
SPLIT line at all
- commit <oid> did not touch the SPLIT line at all! We found the
correct blame for line 3, but the bug is actually in the output
stage, which is showing the wrong line number and content from the
final file.
We can fix this by only coalescing when both the suspect and result
lines are adjacent. That fixes this bug, but keeps coalescing in cases
where want it (e.g., the existing test in t8003 where SPLIT goes away,
and the lines really are adjacent in the result).
Reported-by: Nuthan Munaiah <nm6061@rit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-13 13:25:31 +08:00
|
|
|
test_expect_success 'blame does not coalesce non-adjacent result lines' '
|
2019-06-21 00:38:20 +08:00
|
|
|
cat >expect <<-EOF &&
|
blame: only coalesce lines that are adjacent in result
After blame has finished but before we produce any output, we coalesce
groups of lines that were adjacent in the original suspect (which may
have been split apart by lines in intermediate commits which went away).
However, this can cause incorrect output if the lines are not also
adjacent in the result. For instance, the case in t8003 has:
ABC
DEF
which becomes
ABC
SPLIT
DEF
Blaming only lines 1 and 3 in the result yields two blame groups (one
for each line) that were adjacent in the original. That's enough for us
to coalesce them into a single group, but that loses information: our
output routines assume they're adjacent in the result as well, and we
output:
<oid> 1) ABC
<oid> 2) SPLIT
This is nonsense for two reasons:
- we were asked about line 3, not line 2; we should not output the
SPLIT line at all
- commit <oid> did not touch the SPLIT line at all! We found the
correct blame for line 3, but the bug is actually in the output
stage, which is showing the wrong line number and content from the
final file.
We can fix this by only coalescing when both the suspect and result
lines are adjacent. That fixes this bug, but keeps coalescing in cases
where want it (e.g., the existing test in t8003 where SPLIT goes away,
and the lines really are adjacent in the result).
Reported-by: Nuthan Munaiah <nm6061@rit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-13 13:25:31 +08:00
|
|
|
$orig 1) ABC
|
|
|
|
$orig 3) DEF
|
2019-06-21 00:38:20 +08:00
|
|
|
EOF
|
blame: only coalesce lines that are adjacent in result
After blame has finished but before we produce any output, we coalesce
groups of lines that were adjacent in the original suspect (which may
have been split apart by lines in intermediate commits which went away).
However, this can cause incorrect output if the lines are not also
adjacent in the result. For instance, the case in t8003 has:
ABC
DEF
which becomes
ABC
SPLIT
DEF
Blaming only lines 1 and 3 in the result yields two blame groups (one
for each line) that were adjacent in the original. That's enough for us
to coalesce them into a single group, but that loses information: our
output routines assume they're adjacent in the result as well, and we
output:
<oid> 1) ABC
<oid> 2) SPLIT
This is nonsense for two reasons:
- we were asked about line 3, not line 2; we should not output the
SPLIT line at all
- commit <oid> did not touch the SPLIT line at all! We found the
correct blame for line 3, but the bug is actually in the output
stage, which is showing the wrong line number and content from the
final file.
We can fix this by only coalescing when both the suspect and result
lines are adjacent. That fixes this bug, but keeps coalescing in cases
where want it (e.g., the existing test in t8003 where SPLIT goes away,
and the lines really are adjacent in the result).
Reported-by: Nuthan Munaiah <nm6061@rit.edu>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-13 13:25:31 +08:00
|
|
|
git blame --no-abbrev -s -L1,1 -L3,3 $split giraffe >actual &&
|
2019-06-21 00:38:20 +08:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2007-05-06 13:36:19 +08:00
|
|
|
test_done
|