3 test_description='test log -L'
6 test_expect_success 'setup (import history)' '
8 git fast-import < "$TEST_DIRECTORY"/t4211/history.export &&
15 test_cmp \"\$TEST_DIRECTORY\"/t4211/$(test_oid algo)/expect.$3 actual
20 canned_test_1 success "$@"
22 canned_test_failure () {
23 canned_test_1 failure "$@"
27 test_expect_success "invalid args: $1" "
28 test_must_fail git log $1 2>errors &&
29 test_i18ngrep '$2' errors
33 canned_test "-L 4,12:a.c simple" simple-f
34 canned_test "-L 4,+9:a.c simple" simple-f
35 canned_test "-L '/long f/,/^}/:a.c' simple" simple-f
36 canned_test "-L :f:a.c simple" simple-f-to-main
38 canned_test "-L '/main/,/^}/:a.c' simple" simple-main
39 canned_test "-L :main:a.c simple" simple-main-to-end
41 canned_test "-L 1,+4:a.c simple" beginning-of-file
43 canned_test "-L 20:a.c simple" end-of-file
45 canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges
46 canned_test "-L 24,+1:a.c simple" vanishes-early
48 canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
49 canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
51 canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
52 canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
53 canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
54 canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
55 canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
57 test_bad_opts "-L" "switch.*requires a value"
58 test_bad_opts "-L b.c" "argument not .start,end:file"
59 test_bad_opts "-L 1:" "argument not .start,end:file"
60 test_bad_opts "-L 1:nonexistent" "There is no path"
61 test_bad_opts "-L 1:simple" "There is no path"
62 test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file"
63 test_bad_opts "-L 1000:b.c" "has only.*lines"
64 test_bad_opts "-L :b.c" "argument not .start,end:file"
65 test_bad_opts "-L :foo:b.c" "no match"
67 test_expect_success '-L X (X == nlines)' '
72 test_expect_success '-L X (X == nlines + 1)' '
73 n=$(expr $(wc -l <b.c) + 1) &&
74 test_must_fail git log -L $n:b.c
77 test_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
82 test_expect_success '-L ,Y (Y == nlines)' '
83 n=$(printf "%d" $(wc -l <b.c)) &&
87 test_expect_success '-L ,Y (Y == nlines + 1)' '
88 n=$(expr $(wc -l <b.c) + 1) &&
92 test_expect_success '-L ,Y (Y == nlines + 2)' '
93 n=$(expr $(wc -l <b.c) + 2) &&
97 test_expect_success '-L with --first-parent and a merge' '
98 git checkout parallel-change &&
99 git log --first-parent -L 1,1:b.c
102 test_expect_success '-L with --output' '
103 git checkout parallel-change &&
104 git log --output=log -L :main:b.c >output &&
105 test_must_be_empty output &&
106 test_line_count = 70 log
109 test_expect_success 'range_set_union' '
110 test_seq 500 > c.c &&
112 git commit -m "many lines" &&
113 test_seq 1000 > 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)
119 test_expect_success '-s shows only line-log commits' '
120 git log --format="commit %s" -L1,24:b.c >expect.raw &&
121 grep ^commit expect.raw >expect &&
122 git log --format="commit %s" -L1,24:b.c -s >actual &&
123 test_cmp expect actual
126 test_expect_success '-p shows the default patch output' '
127 git log -L1,24:b.c >expect &&
128 git log -L1,24:b.c -p >actual &&
129 test_cmp expect actual
132 test_expect_success '--raw is forbidden' '
133 test_must_fail git log -L1,24:b.c --raw
136 test_expect_success 'setup for checking fancy rename following' '
137 git checkout --orphan moves-start &&
140 printf "%s\n" 12 13 14 15 b c d e >file-1 &&
141 printf "%s\n" 22 23 24 25 B C D E >file-2 &&
142 git add file-1 file-2 &&
144 git commit -m "Add file-1 and file-2" &&
145 oid_add_f1_f2=$(git rev-parse --short HEAD) &&
147 git checkout -b moves-main &&
148 printf "%s\n" 11 12 13 14 15 b c d e >file-1 &&
149 git commit -a -m "Modify file-1 on main" &&
150 oid_mod_f1_main=$(git rev-parse --short HEAD) &&
152 printf "%s\n" 21 22 23 24 25 B C D E >file-2 &&
153 git commit -a -m "Modify file-2 on main #1" &&
154 oid_mod_f2_main_1=$(git rev-parse --short HEAD) &&
156 git mv file-1 renamed-1 &&
157 git commit -m "Rename file-1 to renamed-1 on main" &&
159 printf "%s\n" 11 12 13 14 15 b c d e f >renamed-1 &&
160 git commit -a -m "Modify renamed-1 on main" &&
161 oid_mod_r1_main=$(git rev-parse --short HEAD) &&
163 printf "%s\n" 21 22 23 24 25 B C D E F >file-2 &&
164 git commit -a -m "Modify file-2 on main #2" &&
165 oid_mod_f2_main_2=$(git rev-parse --short HEAD) &&
167 git checkout -b moves-side moves-start &&
168 printf "%s\n" 12 13 14 15 16 b c d e >file-1 &&
169 git commit -a -m "Modify file-1 on side #1" &&
170 oid_mod_f1_side_1=$(git rev-parse --short HEAD) &&
172 printf "%s\n" 22 23 24 25 26 B C D E >file-2 &&
173 git commit -a -m "Modify file-2 on side" &&
174 oid_mod_f2_side=$(git rev-parse --short HEAD) &&
176 git mv file-2 renamed-2 &&
177 git commit -m "Rename file-2 to renamed-2 on side" &&
179 printf "%s\n" 12 13 14 15 16 a b c d e >file-1 &&
180 git commit -a -m "Modify file-1 on side #2" &&
181 oid_mod_f1_side_2=$(git rev-parse --short HEAD) &&
183 printf "%s\n" 22 23 24 25 26 A B C D E >renamed-2 &&
184 git commit -a -m "Modify renamed-2 on side" &&
185 oid_mod_r2_side=$(git rev-parse --short HEAD) &&
187 git checkout moves-main &&
188 git merge moves-side &&
189 oid_merge=$(git rev-parse --short HEAD)
192 test_expect_success 'fancy rename following #1' '
193 cat >expect <<-EOF &&
194 $oid_merge Merge branch '\''moves-side'\'' into moves-main
195 $oid_mod_f1_side_2 Modify file-1 on side #2
196 $oid_mod_f1_side_1 Modify file-1 on side #1
197 $oid_mod_r1_main Modify renamed-1 on main
198 $oid_mod_f1_main Modify file-1 on main
199 $oid_add_f1_f2 Add file-1 and file-2
201 git log -L1:renamed-1 --oneline --no-patch >actual &&
202 test_cmp expect actual
205 test_expect_success 'fancy rename following #2' '
206 cat >expect <<-EOF &&
207 $oid_merge Merge branch '\''moves-side'\'' into moves-main
208 $oid_mod_r2_side Modify renamed-2 on side
209 $oid_mod_f2_side Modify file-2 on side
210 $oid_mod_f2_main_2 Modify file-2 on main #2
211 $oid_mod_f2_main_1 Modify file-2 on main #1
212 $oid_add_f1_f2 Add file-1 and file-2
214 git log -L1:renamed-2 --oneline --no-patch >actual &&
215 test_cmp expect actual