Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t8011-blame-split-file.sh
blobda1801f4d23edaf15b156d72ab8c98b40fdc3cea
1 #!/bin/sh
3 test_description='
4 The general idea is that we have a single file whose lines come from
5 multiple other files, and those individual files were modified in the same
6 commits. That means that we will see the same commit in multiple contexts,
7 and each one should be attributed to the correct file.
9 Note that we need to use "blame -C" to find the commit for all lines. We will
10 not bother testing that the non-C case fails to find it. That is how blame
11 behaves now, but it is not a property we want to make sure is retained.
14 TEST_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
17 # help avoid typing and reading long strings of similar lines
18 # in the tests below
19 generate_expect () {
20 while read nr data
22 i=0
23 while test $i -lt $nr
25 echo $data
26 i=$((i + 1))
27 done
28 done
31 test_expect_success 'setup split file case' '
32 # use lines long enough to trigger content detection
33 test_seq 1000 1010 >one &&
34 test_seq 2000 2010 >two &&
35 git add one two &&
36 test_commit base &&
38 sed "6s/^/modified /" <one >one.tmp &&
39 mv one.tmp one &&
40 sed "6s/^/modified /" <two >two.tmp &&
41 mv two.tmp two &&
42 git add -u &&
43 test_commit modified &&
45 cat one two >combined &&
46 git add combined &&
47 git rm one two &&
48 test_commit combined
51 test_expect_success 'setup simulated porcelain' '
52 # This just reads porcelain-ish output and tries
53 # to output the value of a given field for each line (either by
54 # reading the field that accompanies this line, or referencing
55 # the information found last time the commit was mentioned).
56 cat >read-porcelain.pl <<-\EOF
57 my $field = shift;
58 while (<>) {
59 if (/^[0-9a-f]{40,} /) {
60 flush();
61 $hash = $&;
62 } elsif (/^$field (.*)/) {
63 $cache{$hash} = $1;
66 flush();
68 sub flush {
69 return unless defined $hash;
70 if (defined $cache{$hash}) {
71 print "$cache{$hash}\n";
72 } else {
73 print "NONE\n";
76 EOF
79 for output in porcelain line-porcelain
81 test_expect_success "generate --$output output" '
82 git blame --root -C --$output combined >output
85 test_expect_success "$output output finds correct commits" '
86 generate_expect >expect <<-\EOF &&
87 5 base
88 1 modified
89 10 base
90 1 modified
91 5 base
92 EOF
93 perl read-porcelain.pl summary <output >actual &&
94 test_cmp expect actual
97 test_expect_success "$output output shows correct filenames" '
98 generate_expect >expect <<-\EOF &&
99 11 one
100 11 two
102 perl read-porcelain.pl filename <output >actual &&
103 test_cmp expect actual
106 test_expect_success "$output output shows correct previous pointer" '
107 generate_expect >expect <<-EOF &&
108 5 NONE
109 1 $(git rev-parse modified^) one
110 10 NONE
111 1 $(git rev-parse modified^) two
112 5 NONE
114 perl read-porcelain.pl previous <output >actual &&
115 test_cmp expect actual
117 done
119 test_done