1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
#!/bin/sh
test_description='git blame with specific diff algorithm'
. ./test-lib.sh
test_expect_success setup '
cat >file.c <<-\EOF &&
int f(int x, int y)
{
if (x == 0)
{
return y;
}
return x;
}
int g(size_t u)
{
while (u < 30)
{
u++;
}
return u;
}
EOF
test_write_lines x x x x >file.txt &&
git add file.c file.txt &&
GIT_AUTHOR_NAME=Commit_1 git commit -m Commit_1 &&
cat >file.c <<-\EOF &&
int g(size_t u)
{
while (u < 30)
{
u++;
}
return u;
}
int h(int x, int y, int z)
{
if (z == 0)
{
return x;
}
return y;
}
EOF
test_write_lines x x x A B C D x E F G >file.txt &&
git add file.c file.txt &&
GIT_AUTHOR_NAME=Commit_2 git commit -m Commit_2
'
test_expect_success 'blame uses Myers diff algorithm by default' '
cat >expected <<-\EOF &&
Commit_2 int g(size_t u)
Commit_1 {
Commit_2 while (u < 30)
Commit_1 {
Commit_2 u++;
Commit_1 }
Commit_2 return u;
Commit_1 }
Commit_1
Commit_2 int h(int x, int y, int z)
Commit_1 {
Commit_2 if (z == 0)
Commit_1 {
Commit_2 return x;
Commit_1 }
Commit_2 return y;
Commit_1 }
EOF
git blame file.c >output &&
sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output >without_varying_parts &&
sed -e "s/ *$//g" without_varying_parts >actual &&
test_cmp expected actual
'
test_expect_success 'blame honors --diff-algorithm option' '
cat >expected <<-\EOF &&
Commit_1 int g(size_t u)
Commit_1 {
Commit_1 while (u < 30)
Commit_1 {
Commit_1 u++;
Commit_1 }
Commit_1 return u;
Commit_1 }
Commit_2
Commit_2 int h(int x, int y, int z)
Commit_2 {
Commit_2 if (z == 0)
Commit_2 {
Commit_2 return x;
Commit_2 }
Commit_2 return y;
Commit_2 }
EOF
git blame file.c --diff-algorithm histogram >output &&
sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output >without_varying_parts &&
sed -e "s/ *$//g" without_varying_parts >actual &&
test_cmp expected actual
'
test_expect_success 'blame honors diff.algorithm config variable' '
cat >expected <<-\EOF &&
Commit_1 int g(size_t u)
Commit_1 {
Commit_1 while (u < 30)
Commit_1 {
Commit_1 u++;
Commit_1 }
Commit_1 return u;
Commit_1 }
Commit_2
Commit_2 int h(int x, int y, int z)
Commit_2 {
Commit_2 if (z == 0)
Commit_2 {
Commit_2 return x;
Commit_2 }
Commit_2 return y;
Commit_2 }
EOF
git -c diff.algorithm=histogram blame file.c >output &&
sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" \
-e "s/ *$//g" output >actual &&
test_cmp expected actual
'
test_expect_success 'blame gives priority to --diff-algorithm over diff.algorithm' '
cat >expected <<-\EOF &&
Commit_1 int g(size_t u)
Commit_1 {
Commit_1 while (u < 30)
Commit_1 {
Commit_1 u++;
Commit_1 }
Commit_1 return u;
Commit_1 }
Commit_2
Commit_2 int h(int x, int y, int z)
Commit_2 {
Commit_2 if (z == 0)
Commit_2 {
Commit_2 return x;
Commit_2 }
Commit_2 return y;
Commit_2 }
EOF
git -c diff.algorithm=myers blame file.c --diff-algorithm histogram >output &&
sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" \
-e "s/ *$//g" output >actual &&
test_cmp expected actual
'
test_expect_success 'blame honors --minimal option' '
cat >expected <<-\EOF &&
Commit_1 x
Commit_1 x
Commit_1 x
Commit_2 A
Commit_2 B
Commit_2 C
Commit_2 D
Commit_1 x
Commit_2 E
Commit_2 F
Commit_2 G
EOF
git blame file.txt --minimal >output &&
sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output >actual &&
test_cmp expected actual
'
test_expect_success 'blame respects the order of diff options' '
cat >expected <<-\EOF &&
Commit_1 x
Commit_1 x
Commit_1 x
Commit_2 A
Commit_2 B
Commit_2 C
Commit_2 D
Commit_2 x
Commit_2 E
Commit_2 F
Commit_2 G
EOF
git blame file.txt --minimal --diff-algorithm myers >output &&
sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output >actual &&
test_cmp expected actual
'
test_done
|