1 # Helpers shared by the test scripts for diff algorithms (patience,
12 for(i
= 0; i
< 10; i
++)
14 printf("Your answer is: ");
28 int main
(int argc
, char
**argv
)
41 return fib
(n-1
) + fib
(n-2
);
50 for(i
= 0; i
< 10; i
++)
56 int main
(int argc
, char
**argv
)
62 file1
=$
(git rev-parse
--short $
(git hash-object file1
))
63 file2
=$
(git rev-parse
--short $
(git hash-object file2
))
65 diff --git a/file1 b/file2
66 index $file1..$file2 100644
76 + return fib(n-1) + fib(n-2);
85 for(i = 0; i < 10; i++)
87 - printf("Your answer is: ");
96 - return fact(n-1) * n;
101 int main(int argc, char **argv)
103 - frobnitz(fact(10));
108 cat >expect_diffstat
<<EOF
109 file1 => file2 | 21 ++++++++++-----------
110 1 file changed, 10 insertions(+), 11 deletions(-)
115 test_expect_success
"setup attributes files for tests with $STRATEGY" '
116 git checkout -b master &&
117 echo "file* diff=driver" >.gitattributes &&
118 git add file1 file2 .gitattributes &&
119 git commit -m "adding files" &&
120 git checkout -b branchA &&
121 echo "file* diff=driverA" >.gitattributes &&
122 git add .gitattributes &&
123 git commit -m "adding driverA as diff driver" &&
124 git checkout master &&
125 git clone --bare --no-local . bare.git
128 test_expect_success
"$STRATEGY diff from attributes" '
129 test_must_fail git -c diff.driver.algorithm=$STRATEGY diff --no-index file1 file2 > output &&
130 test_cmp expect output
133 test_expect_success
"diff from attributes with bare repo with source" '
134 git -C bare.git --attr-source=branchA -c diff.driver.algorithm=myers \
135 -c diff.driverA.algorithm=$STRATEGY \
136 diff HEAD:file1 HEAD:file2 >output &&
137 test_cmp expect output
140 test_expect_success
"diff from attributes with bare repo with invalid source" '
141 test_must_fail git -C bare.git --attr-source=invalid-branch diff \
142 HEAD:file1 HEAD:file2
145 test_expect_success
"$STRATEGY diff from attributes has valid diffstat" '
146 echo "file* diff=driver" >.gitattributes &&
147 git config diff.driver.algorithm "$STRATEGY" &&
148 test_must_fail git diff --stat --no-index file1 file2 > output &&
149 test_cmp expect_diffstat output
152 test_expect_success
"$STRATEGY diff" '
153 test_must_fail git diff --no-index "--diff-algorithm=$STRATEGY" file1 file2 > output &&
154 test_cmp expect output
157 test_expect_success
"$STRATEGY diff command line precedence before attributes" '
158 echo "file* diff=driver" >.gitattributes &&
159 git config diff.driver.algorithm myers &&
160 test_must_fail git diff --no-index "--diff-algorithm=$STRATEGY" file1 file2 > output &&
161 test_cmp expect output
164 test_expect_success
"$STRATEGY diff attributes precedence before config" '
165 git config diff.algorithm default &&
166 echo "file* diff=driver" >.gitattributes &&
167 git config diff.driver.algorithm "$STRATEGY" &&
168 test_must_fail git diff --no-index file1 file2 > output &&
169 test_cmp expect output
172 test_expect_success
"$STRATEGY diff output is valid" '
174 git apply < output &&
175 test_cmp expect file2
198 uniq1
=$
(git rev-parse
--short $
(git hash-object uniq1
))
199 uniq2
=$
(git rev-parse
--short $
(git hash-object uniq2
))
201 diff --git a/uniq1 b/uniq2
202 index $uniq1..$uniq2 100644
222 test_expect_success
'completely different files' '
223 test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
224 test_cmp expect output