3 # Copyright (c) 2010 Bo Yang
6 test_description
='Test git log -L with single line of history'
9 .
"$TEST_DIRECTORY"/diff-lib.sh
24 printf("hello world");
28 test_expect_success
'add path0/path1 and commit.' '
29 git add path0 path1 &&
30 git commit -m "Base commit"
46 const char
*str
= "hello world!";
51 test_expect_success
'Change the 2,3 lines of path0 and path1.' '
52 git add path0 path1 &&
53 git commit -m "Change 2,3 lines of path0 and path1"
66 test_expect_success
'Change the 5th line of path0.' '
68 git commit -m "Change the 5th line of path0"
80 test_expect_success
'Final change of path0.' '
82 git commit -m "Final change of path0"
85 cat >expected-path0
<<\EOF
88 diff --git a
/path0 b
/path0
89 index ccdf243..ccf8bcf
100644
99 + printf("%d", a
- b
);
102 Change the
5th line of path0
104 diff --git a
/path0 b
/path0
105 index b0eb888..ccdf243
100644
118 Change
2,3 lines of path0 and path1
120 diff --git a
/path0 b
/path0
121 index fb33939..b0eb888
100644
137 diff --git a
/path0 b
/path0
139 index
0000000..fb33939
152 cat >expected-path1
<<\EOF
153 Change
2,3 lines of path0 and path1
155 diff --git a
/path1 b
/path1
156 index
52be2a5..cc54b12
100644
162 - printf("hello world");
163 + const char
*str
= "hello world!";
169 diff --git a
/path1 b
/path1
171 index
0000000.
.52be2a5
177 + printf("hello world");
181 cat >expected-pathall
<<\EOF
182 Final change of path0
184 diff --git a
/path0 b
/path0
185 index ccdf243..ccf8bcf
100644
195 + printf("%d", a
- b
);
198 Change the
5th line of path0
200 diff --git a
/path0 b
/path0
201 index b0eb888..ccdf243
100644
214 Change
2,3 lines of path0 and path1
216 diff --git a
/path0 b
/path0
217 index fb33939..b0eb888
100644
230 diff --git a
/path1 b
/path1
231 index
52be2a5..cc54b12
100644
237 - printf("hello world");
238 + const char
*str
= "hello world!";
244 diff --git a
/path0 b
/path0
246 index
0000000..fb33939
257 diff --git a
/path1 b
/path1
259 index
0000000.
.52be2a5
265 + printf("hello world");
269 cat >expected-linenum
<<\EOF
270 Change
2,3 lines of path0 and path1
272 diff --git a
/path0 b
/path0
273 index fb33939..b0eb888
100644
285 diff --git a
/path0 b
/path0
287 index
0000000..fb33939
296 cat >expected-always
<<\EOF
297 Final change of path0
299 diff --git a
/path0 b
/path0
300 index ccdf243..ccf8bcf
100644
308 Change the
5th line of path0
310 diff --git a
/path0 b
/path0
311 index b0eb888..ccdf243
100644
319 Change
2,3 lines of path0 and path1
321 diff --git a
/path0 b
/path0
322 index fb33939..b0eb888
100644
334 diff --git a
/path0 b
/path0
336 index
0000000..fb33939
345 test_expect_success
'Show the line level log of path0' '
346 git log --pretty=format:%s%n%b -L /func/,/^}/ path0 > current-path0
349 test_expect_success
'validate the path0 output.' '
350 test_cmp current-path0 expected-path0
353 test_expect_success
'Show the line level log of path1' '
354 git log --pretty=format:%s%n%b -L /output/,/^}/ path1 > current-path1
357 test_expect_success
'validate the path1 output.' '
358 test_cmp current-path1 expected-path1
361 test_expect_success
'Show the line level log of two files' '
362 git log --pretty=format:%s%n%b -L /func/,/^}/ path0 -L /output/,/^}/ path1 > current-pathall
365 test_expect_success
'validate the all path output.' '
366 test_cmp current-pathall expected-pathall
369 test_expect_success
'Test the line number argument' '
370 git log --pretty=format:%s%n%b -L 2,4 path0 > current-linenum
373 test_expect_success
'validate the line number output.' '
374 test_cmp current-linenum expected-linenum
376 test_expect_success
'Test the --full-line-diff option' '
377 git log --pretty=format:%s%n%b --full-line-diff -L 2,4 path0 > current-always
380 test_expect_success
'validate the --full-line-diff output.' '
381 test_cmp current-always expected-always
384 # Rerun all log with graph
385 test_expect_success
'Show the line level log of path0 with --graph' '
386 git log --pretty=format:%s%n%b --graph -L /func/,/^}/ path0 > current-path0-graph
389 test_expect_success
'Show the line level log of path1 with --graph' '
390 git log --pretty=format:%s%n%b --graph -L /output/,/^}/ path1 > current-path1-graph
393 test_expect_success
'Show the line level log of two files with --graph' '
394 git log --pretty=format:%s%n%b --graph -L /func/,/^}/ path0 --graph -L /output/,/^}/ path1 > current-pathall-graph
397 test_expect_success
'Test the line number argument with --graph' '
398 git log --pretty=format:%s%n%b --graph -L 2,4 path0 > current-linenum-graph
401 test_expect_success
'Test the --full-line-diff option with --graph option' '
402 git log --pretty=format:%s%n%b --full-line-diff --graph -L 2,4 path0 > current-always-graph
405 cat > expected-path0-graph
<<\EOF
406 * Final change of path0
408 |
diff --git a
/path0 b
/path0
409 | index ccdf243..ccf8bcf
100644
418 |
- c
= 10 * (a
+ b
);
419 |
+ printf("%d", a
- b
);
422 * Change the
5th line of path0
424 |
diff --git a
/path0 b
/path0
425 | index b0eb888..ccdf243
100644
435 |
+ c
= 10 * (a
+ b
);
438 * Change
2,3 lines of path0 and path1
440 |
diff --git a
/path0 b
/path0
441 | index fb33939..b0eb888
100644
457 diff --git a
/path0 b
/path0
459 index
0000000..fb33939
472 cat > expected-path1-graph
<<\EOF
473 * Change
2,3 lines of path0 and path1
475 |
diff --git a
/path1 b
/path1
476 | index
52be2a5..cc54b12
100644
482 |
- printf("hello world");
483 |
+ const char
*str
= "hello world!";
484 |
+ printf("%s", str
);
489 diff --git a
/path1 b
/path1
491 index
0000000.
.52be2a5
497 + printf("hello world");
501 cat > expected-pathall-graph
<<\EOF
502 * Final change of path0
504 |
diff --git a
/path0 b
/path0
505 | index ccdf243..ccf8bcf
100644
514 |
- c
= 10 * (a
+ b
);
515 |
+ printf("%d", a
- b
);
518 * Change the
5th line of path0
520 |
diff --git a
/path0 b
/path0
521 | index b0eb888..ccdf243
100644
531 |
+ c
= 10 * (a
+ b
);
534 * Change
2,3 lines of path0 and path1
536 |
diff --git a
/path0 b
/path0
537 | index fb33939..b0eb888
100644
550 |
diff --git a
/path1 b
/path1
551 | index
52be2a5..cc54b12
100644
557 |
- printf("hello world");
558 |
+ const char
*str
= "hello world!";
559 |
+ printf("%s", str
);
564 diff --git a
/path0 b
/path0
566 index
0000000..fb33939
577 diff --git a
/path1 b
/path1
579 index
0000000.
.52be2a5
585 + printf("hello world");
589 cat > expected-linenum-graph
<<\EOF
590 * Change
2,3 lines of path0 and path1
592 |
diff --git a
/path0 b
/path0
593 | index fb33939..b0eb888
100644
605 diff --git a
/path0 b
/path0
607 index
0000000..fb33939
616 cat > expected-always-graph
<<\EOF
617 * Final change of path0
619 |
diff --git a
/path0 b
/path0
620 | index ccdf243..ccf8bcf
100644
628 * Change the
5th line of path0
630 |
diff --git a
/path0 b
/path0
631 | index b0eb888..ccdf243
100644
639 * Change
2,3 lines of path0 and path1
641 |
diff --git a
/path0 b
/path0
642 | index fb33939..b0eb888
100644
654 diff --git a
/path0 b
/path0
656 index
0000000..fb33939
665 test_expect_success
'validate the path0 output.' '
666 test_cmp current-path0-graph expected-path0-graph
669 test_expect_success
'validate the path1 output.' '
670 test_cmp current-path1-graph expected-path1-graph
673 test_expect_success
'validate the all path output.' '
674 test_cmp current-pathall-graph expected-pathall-graph
677 test_expect_success
'validate graph output' '
678 test_cmp current-linenum-graph expected-linenum-graph
681 test_expect_success
'validate --full-line-diff output' '
682 test_cmp current-always-graph expected-always-graph