interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t8011-blame-split-file.sh

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