blob: d0377fae5c832bcd4df37f3bc2ab4a8708f70251 [file] [log] [blame]
Thomas Rast12da1d12013-03-28 17:47:32 +01001#!/bin/sh
2
3test_description='test log -L'
4. ./test-lib.sh
5
6test_expect_success 'setup (import history)' '
7 git fast-import < "$TEST_DIRECTORY"/t4211/history.export &&
8 git reset --hard
9'
10
Thomas Rastd51c5272013-04-12 18:05:10 +020011canned_test_1 () {
12 test_expect_$1 "$2" "
13 git log $2 >actual &&
14 test_cmp \"\$TEST_DIRECTORY\"/t4211/expect.$3 actual
Thomas Rast12da1d12013-03-28 17:47:32 +010015 "
16}
17
Thomas Rastd51c5272013-04-12 18:05:10 +020018canned_test () {
19 canned_test_1 success "$@"
20}
21canned_test_failure () {
22 canned_test_1 failure "$@"
23}
24
Thomas Rast12da1d12013-03-28 17:47:32 +010025test_bad_opts () {
26 test_expect_success "invalid args: $1" "
27 test_must_fail git log $1 2>errors &&
28 grep '$2' errors
29 "
30}
31
32canned_test "-L 4,12:a.c simple" simple-f
33canned_test "-L 4,+9:a.c simple" simple-f
34canned_test "-L '/long f/,/^}/:a.c' simple" simple-f
Thomas Rast13b8f682013-03-28 17:47:33 +010035canned_test "-L :f:a.c simple" simple-f-to-main
Thomas Rast12da1d12013-03-28 17:47:32 +010036
37canned_test "-L '/main/,/^}/:a.c' simple" simple-main
Thomas Rast13b8f682013-03-28 17:47:33 +010038canned_test "-L :main:a.c simple" simple-main-to-end
Thomas Rast12da1d12013-03-28 17:47:32 +010039
40canned_test "-L 1,+4:a.c simple" beginning-of-file
41
42canned_test "-L 20:a.c simple" end-of-file
43
44canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges
45canned_test "-L 24,+1:a.c simple" vanishes-early
46
Thomas Rast035ff392013-04-12 18:05:09 +020047canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
Thomas Rast31c61912013-04-12 18:05:11 +020048canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
Thomas Rast12da1d12013-03-28 17:47:32 +010049
Thomas Rast20961882013-04-05 16:34:48 +020050canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
Eric Sunshine215e76c2013-08-06 09:59:47 -040051canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
Thomas Rast20961882013-04-05 16:34:48 +020052canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
Eric Sunshine3755b532013-07-09 01:55:05 -040053canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
54canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
Thomas Rast20961882013-04-05 16:34:48 +020055
Thomas Rast12da1d12013-03-28 17:47:32 +010056test_bad_opts "-L" "switch.*requires a value"
Matthieu Moy0269f962015-04-20 14:09:07 +020057test_bad_opts "-L b.c" "argument not .start,end:file"
58test_bad_opts "-L 1:" "argument not .start,end:file"
Thomas Rast12da1d12013-03-28 17:47:32 +010059test_bad_opts "-L 1:nonexistent" "There is no path"
60test_bad_opts "-L 1:simple" "There is no path"
Matthieu Moy0269f962015-04-20 14:09:07 +020061test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file"
Thomas Rast12da1d12013-03-28 17:47:32 +010062test_bad_opts "-L 1000:b.c" "has only.*lines"
63test_bad_opts "-L 1,1000:b.c" "has only.*lines"
Matthieu Moy0269f962015-04-20 14:09:07 +020064test_bad_opts "-L :b.c" "argument not .start,end:file"
Thomas Rast13b8f682013-03-28 17:47:33 +010065test_bad_opts "-L :foo:b.c" "no match"
Thomas Rast12da1d12013-03-28 17:47:32 +010066
Eric Sunshine25fb8ee2013-07-31 04:15:39 -040067test_expect_success '-L X (X == nlines)' '
68 n=$(wc -l <b.c) &&
69 git log -L $n:b.c
70'
71
Eric Sunshine63828b82013-07-31 04:15:41 -040072test_expect_success '-L X (X == nlines + 1)' '
Eric Sunshine25fb8ee2013-07-31 04:15:39 -040073 n=$(expr $(wc -l <b.c) + 1) &&
74 test_must_fail git log -L $n:b.c
75'
76
77test_expect_success '-L X (X == nlines + 2)' '
78 n=$(expr $(wc -l <b.c) + 2) &&
79 test_must_fail git log -L $n:b.c
80'
81
82test_expect_success '-L ,Y (Y == nlines)' '
83 n=$(printf "%d" $(wc -l <b.c)) &&
84 git log -L ,$n:b.c
85'
86
87test_expect_success '-L ,Y (Y == nlines + 1)' '
88 n=$(expr $(wc -l <b.c) + 1) &&
89 test_must_fail git log -L ,$n:b.c
90'
91
92test_expect_success '-L ,Y (Y == nlines + 2)' '
93 n=$(expr $(wc -l <b.c) + 2) &&
94 test_must_fail git log -L ,$n:b.c
95'
96
Tzvetan Mikova8787c52014-11-04 12:33:37 -080097test_expect_success '-L with --first-parent and a merge' '
98 git checkout parallel-change &&
99 git log --first-parent -L 1,1:b.c
100'
101
Johannes Schindelinc1496932016-06-22 17:02:13 +0200102test_expect_success '-L with --output' '
103 git checkout parallel-change &&
104 git log --output=log -L :main:b.c >output &&
105 test ! -s output &&
106 test_line_count = 70 log
107'
108
Allan Xavieraaae0bf2017-03-02 17:29:02 +0000109test_expect_success 'range_set_union' '
110 test_seq 500 > c.c &&
111 git add c.c &&
112 git commit -m "many lines" &&
113 test_seq 1000 > c.c &&
114 git add c.c &&
115 git commit -m "modify many lines" &&
116 git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
117'
118
Thomas Rast12da1d12013-03-28 17:47:32 +0100119test_done