Do not strip CR when grepping HTTP headers.
[git/dscho.git] / t / t4301-log-line-single-history.sh
blob3197ea8138ec7f0d47571969219788d2dcc59e92
1 #!/bin/sh
3 # Copyright (c) 2010 Bo Yang
6 test_description='Test git log -L with single line of history'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/diff-lib.sh
11 cat >path0 <<\EOF
12 void func()
14 int a = 0;
15 int b = 1;
16 int c;
17 c = a + b;
19 EOF
21 cat >path1 <<\EOF
22 void output()
24 printf("hello world");
26 EOF
28 test_expect_success 'add path0/path1 and commit.' '
29 git add path0 path1 &&
30 git commit -m "Base commit"
33 cat >path0 <<\EOF
34 void func()
36 int a = 10;
37 int b = 11;
38 int c;
39 c = a + b;
41 EOF
43 cat >path1 <<\EOF
44 void output()
46 const char *str = "hello world!";
47 printf("%s", str);
49 EOF
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"
56 cat >path0 <<\EOF
57 void func()
59 int a = 10;
60 int b = 11;
61 int c;
62 c = 10 * (a + b);
64 EOF
66 test_expect_success 'Change the 5th line of path0.' '
67 git add path0 &&
68 git commit -m "Change the 5th line of path0"
71 cat >path0 <<\EOF
72 void func()
74 int a = 10;
75 int b = 11;
76 printf("%d", a - b);
78 EOF
80 test_expect_success 'Final change of path0.' '
81 git add path0 &&
82 git commit -m "Final change of path0"
85 cat >expected-path0 <<\EOF
86 Final change of path0
88 diff --git a/path0 b/path0
89 index ccdf243..ccf8bcf 100644
90 --- a/path0
91 +++ b/path0
92 @@ -1,7 +1,6 @@
93 void func()
95 int a = 10;
96 int b = 11;
97 - int c;
98 - c = 10 * (a + b);
99 + printf("%d", a - b);
102 Change the 5th line of path0
104 diff --git a/path0 b/path0
105 index b0eb888..ccdf243 100644
106 --- a/path0
107 +++ b/path0
108 @@ -1,7 +1,7 @@
109 void func()
111 int a = 10;
112 int b = 11;
113 int c;
114 - c = a + b;
115 + c = 10 * (a + b);
118 Change 2,3 lines of path0 and path1
120 diff --git a/path0 b/path0
121 index fb33939..b0eb888 100644
122 --- a/path0
123 +++ b/path0
124 @@ -1,7 +1,7 @@
125 void func()
127 - int a = 0;
128 - int b = 1;
129 + int a = 10;
130 + int b = 11;
131 int c;
132 c = a + b;
135 Base commit
137 diff --git a/path0 b/path0
138 new file mode 100644
139 index 0000000..fb33939
140 --- /dev/null
141 +++ b/path0
142 @@ -0,0 +1,7 @@
143 +void func()
145 + int a = 0;
146 + int b = 1;
147 + int c;
148 + c = a + b;
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
157 --- a/path1
158 +++ b/path1
159 @@ -1,4 +1,5 @@
160 void output()
162 - printf("hello world");
163 + const char *str = "hello world!";
164 + printf("%s", str);
167 Base commit
169 diff --git a/path1 b/path1
170 new file mode 100644
171 index 0000000..52be2a5
172 --- /dev/null
173 +++ b/path1
174 @@ -0,0 +1,4 @@
175 +void output()
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
186 --- a/path0
187 +++ b/path0
188 @@ -1,7 +1,6 @@
189 void func()
191 int a = 10;
192 int b = 11;
193 - int c;
194 - c = 10 * (a + b);
195 + printf("%d", a - b);
198 Change the 5th line of path0
200 diff --git a/path0 b/path0
201 index b0eb888..ccdf243 100644
202 --- a/path0
203 +++ b/path0
204 @@ -1,7 +1,7 @@
205 void func()
207 int a = 10;
208 int b = 11;
209 int c;
210 - c = a + b;
211 + c = 10 * (a + b);
214 Change 2,3 lines of path0 and path1
216 diff --git a/path0 b/path0
217 index fb33939..b0eb888 100644
218 --- a/path0
219 +++ b/path0
220 @@ -1,7 +1,7 @@
221 void func()
223 - int a = 0;
224 - int b = 1;
225 + int a = 10;
226 + int b = 11;
227 int c;
228 c = a + b;
230 diff --git a/path1 b/path1
231 index 52be2a5..cc54b12 100644
232 --- a/path1
233 +++ b/path1
234 @@ -1,4 +1,5 @@
235 void output()
237 - printf("hello world");
238 + const char *str = "hello world!";
239 + printf("%s", str);
242 Base commit
244 diff --git a/path0 b/path0
245 new file mode 100644
246 index 0000000..fb33939
247 --- /dev/null
248 +++ b/path0
249 @@ -0,0 +1,7 @@
250 +void func()
252 + int a = 0;
253 + int b = 1;
254 + int c;
255 + c = a + b;
257 diff --git a/path1 b/path1
258 new file mode 100644
259 index 0000000..52be2a5
260 --- /dev/null
261 +++ b/path1
262 @@ -0,0 +1,4 @@
263 +void output()
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
274 --- a/path0
275 +++ b/path0
276 @@ -2,3 +2,3 @@
278 - int a = 0;
279 - int b = 1;
280 + int a = 10;
281 + int b = 11;
283 Base commit
285 diff --git a/path0 b/path0
286 new file mode 100644
287 index 0000000..fb33939
288 --- /dev/null
289 +++ b/path0
290 @@ -0,0 +2,3 @@
292 + int a = 0;
293 + int b = 1;
296 cat >expected-always <<\EOF
297 Final change of path0
299 diff --git a/path0 b/path0
300 index ccdf243..ccf8bcf 100644
301 --- a/path0
302 +++ b/path0
303 @@ -2,3 +2,3 @@
305 int a = 10;
306 int b = 11;
308 Change the 5th line of path0
310 diff --git a/path0 b/path0
311 index b0eb888..ccdf243 100644
312 --- a/path0
313 +++ b/path0
314 @@ -2,3 +2,3 @@
316 int a = 10;
317 int b = 11;
319 Change 2,3 lines of path0 and path1
321 diff --git a/path0 b/path0
322 index fb33939..b0eb888 100644
323 --- a/path0
324 +++ b/path0
325 @@ -2,3 +2,3 @@
327 - int a = 0;
328 - int b = 1;
329 + int a = 10;
330 + int b = 11;
332 Base commit
334 diff --git a/path0 b/path0
335 new file mode 100644
336 index 0000000..fb33939
337 --- /dev/null
338 +++ b/path0
339 @@ -0,0 +2,3 @@
341 + int a = 0;
342 + int b = 1;
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
410 | --- a/path0
411 | +++ b/path0
412 | @@ -1,7 +1,6 @@
413 | void func()
415 | int a = 10;
416 | int b = 11;
417 | - int c;
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
426 | --- a/path0
427 | +++ b/path0
428 | @@ -1,7 +1,7 @@
429 | void func()
431 | int a = 10;
432 | int b = 11;
433 | int c;
434 | - c = a + b;
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
442 | --- a/path0
443 | +++ b/path0
444 | @@ -1,7 +1,7 @@
445 | void func()
447 | - int a = 0;
448 | - int b = 1;
449 | + int a = 10;
450 | + int b = 11;
451 | int c;
452 | c = a + b;
455 * Base commit
457 diff --git a/path0 b/path0
458 new file mode 100644
459 index 0000000..fb33939
460 --- /dev/null
461 +++ b/path0
462 @@ -0,0 +1,7 @@
463 +void func()
465 + int a = 0;
466 + int b = 1;
467 + int c;
468 + c = a + b;
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
477 | --- a/path1
478 | +++ b/path1
479 | @@ -1,4 +1,5 @@
480 | void output()
482 | - printf("hello world");
483 | + const char *str = "hello world!";
484 | + printf("%s", str);
487 * Base commit
489 diff --git a/path1 b/path1
490 new file mode 100644
491 index 0000000..52be2a5
492 --- /dev/null
493 +++ b/path1
494 @@ -0,0 +1,4 @@
495 +void output()
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
506 | --- a/path0
507 | +++ b/path0
508 | @@ -1,7 +1,6 @@
509 | void func()
511 | int a = 10;
512 | int b = 11;
513 | - int c;
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
522 | --- a/path0
523 | +++ b/path0
524 | @@ -1,7 +1,7 @@
525 | void func()
527 | int a = 10;
528 | int b = 11;
529 | int c;
530 | - c = a + b;
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
538 | --- a/path0
539 | +++ b/path0
540 | @@ -1,7 +1,7 @@
541 | void func()
543 | - int a = 0;
544 | - int b = 1;
545 | + int a = 10;
546 | + int b = 11;
547 | int c;
548 | c = a + b;
550 | diff --git a/path1 b/path1
551 | index 52be2a5..cc54b12 100644
552 | --- a/path1
553 | +++ b/path1
554 | @@ -1,4 +1,5 @@
555 | void output()
557 | - printf("hello world");
558 | + const char *str = "hello world!";
559 | + printf("%s", str);
562 * Base commit
564 diff --git a/path0 b/path0
565 new file mode 100644
566 index 0000000..fb33939
567 --- /dev/null
568 +++ b/path0
569 @@ -0,0 +1,7 @@
570 +void func()
572 + int a = 0;
573 + int b = 1;
574 + int c;
575 + c = a + b;
577 diff --git a/path1 b/path1
578 new file mode 100644
579 index 0000000..52be2a5
580 --- /dev/null
581 +++ b/path1
582 @@ -0,0 +1,4 @@
583 +void output()
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
594 | --- a/path0
595 | +++ b/path0
596 | @@ -2,3 +2,3 @@
598 | - int a = 0;
599 | - int b = 1;
600 | + int a = 10;
601 | + int b = 11;
603 * Base commit
605 diff --git a/path0 b/path0
606 new file mode 100644
607 index 0000000..fb33939
608 --- /dev/null
609 +++ b/path0
610 @@ -0,0 +2,3 @@
612 + int a = 0;
613 + int b = 1;
616 cat > expected-always-graph <<\EOF
617 * Final change of path0
619 | diff --git a/path0 b/path0
620 | index ccdf243..ccf8bcf 100644
621 | --- a/path0
622 | +++ b/path0
623 | @@ -2,3 +2,3 @@
625 | int a = 10;
626 | int b = 11;
628 * Change the 5th line of path0
630 | diff --git a/path0 b/path0
631 | index b0eb888..ccdf243 100644
632 | --- a/path0
633 | +++ b/path0
634 | @@ -2,3 +2,3 @@
636 | int a = 10;
637 | int b = 11;
639 * Change 2,3 lines of path0 and path1
641 | diff --git a/path0 b/path0
642 | index fb33939..b0eb888 100644
643 | --- a/path0
644 | +++ b/path0
645 | @@ -2,3 +2,3 @@
647 | - int a = 0;
648 | - int b = 1;
649 | + int a = 10;
650 | + int b = 11;
652 * Base commit
654 diff --git a/path0 b/path0
655 new file mode 100644
656 index 0000000..fb33939
657 --- /dev/null
658 +++ b/path0
659 @@ -0,0 +2,3 @@
661 + int a = 0;
662 + int b = 1;
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
685 test_done