3 test_description='test log -L'
6 test_expect_success 'setup (import history)' '
7 git fast-import < "$TEST_DIRECTORY"/t4211/history.export &&
11 test_expect_success 'basic command line parsing' '
12 # This may fail due to "no such path a.c in commit", or
13 # "-L is incompatible with pathspec", depending on the
14 # order the error is checked. Either is acceptable.
15 test_must_fail git log -L1,1:a.c -- a.c &&
17 # -L requires there is no pathspec
18 test_must_fail git log -L1,1:b.c -- b.c 2>error &&
19 test_i18ngrep "cannot be used with pathspec" error &&
21 # This would fail because --follow wants a single path, but
22 # we may fail due to incompatibility between -L/--follow in
23 # the future. Either is acceptable.
24 test_must_fail git log -L1,1:b.c --follow &&
25 test_must_fail git log --follow -L1,1:b.c &&
27 # This would fail because -L wants no pathspec, but
28 # we may fail due to incompatibility between -L/--follow in
29 # the future. Either is acceptable.
30 test_must_fail git log --follow -L1,1:b.c -- b.c
36 test_cmp \"\$TEST_DIRECTORY\"/t4211/$(test_oid algo)/expect.$3 actual
41 canned_test_1 success "$@"
43 canned_test_failure () {
44 canned_test_1 failure "$@"
48 test_expect_success "invalid args: $1" "
49 test_must_fail git log $1 2>errors &&
50 test_i18ngrep '$2' errors
54 canned_test "-L 4,12:a.c simple" simple-f
55 canned_test "-L 4,+9:a.c simple" simple-f
56 canned_test "-L '/long f/,/^}/:a.c' simple" simple-f
57 canned_test "-L :f:a.c simple" simple-f-to-main
59 canned_test "-L '/main/,/^}/:a.c' simple" simple-main
60 canned_test "-L :main:a.c simple" simple-main-to-end
62 canned_test "-L 1,+4:a.c simple" beginning-of-file
64 canned_test "-L 20:a.c simple" end-of-file
66 canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges
67 canned_test "-L 24,+1:a.c simple" vanishes-early
69 canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
70 canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
72 canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
73 canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
74 canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
75 canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
76 canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
78 test_bad_opts "-L" "switch.*requires a value"
79 test_bad_opts "-L b.c" "argument not .start,end:file"
80 test_bad_opts "-L 1:" "argument not .start,end:file"
81 test_bad_opts "-L 1:nonexistent" "There is no path"
82 test_bad_opts "-L 1:simple" "There is no path"
83 test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file"
84 test_bad_opts "-L 1000:b.c" "has only.*lines"
85 test_bad_opts "-L :b.c" "argument not .start,end:file"
86 test_bad_opts "-L :foo:b.c" "no match"
88 test_expect_success '-L X (X == nlines)' '
93 test_expect_success '-L X (X == nlines + 1)' '
94 n=$(expr $(wc -l <b.c) + 1) &&
95 test_must_fail git log -L $n:b.c
98 test_expect_success '-L X (X == nlines + 2)' '
99 n=$(expr $(wc -l <b.c) + 2) &&
100 test_must_fail git log -L $n:b.c
103 test_expect_success '-L ,Y (Y == nlines)' '
104 n=$(printf "%d" $(wc -l <b.c)) &&
108 test_expect_success '-L ,Y (Y == nlines + 1)' '
109 n=$(expr $(wc -l <b.c) + 1) &&
113 test_expect_success '-L ,Y (Y == nlines + 2)' '
114 n=$(expr $(wc -l <b.c) + 2) &&
118 test_expect_success '-L with --first-parent and a merge' '
119 git checkout parallel-change &&
120 git log --first-parent -L 1,1:b.c
123 test_expect_success '-L with --output' '
124 git checkout parallel-change &&
125 git log --output=log -L :main:b.c >output &&
126 test_must_be_empty output &&
127 test_line_count = 70 log
130 test_expect_success 'range_set_union' '
131 test_seq 500 > c.c &&
133 git commit -m "many lines" &&
134 test_seq 1000 > c.c &&
136 git commit -m "modify many lines" &&
137 git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
140 test_expect_success '-s shows only line-log commits' '
141 git log --format="commit %s" -L1,24:b.c >expect.raw &&
142 grep ^commit expect.raw >expect &&
143 git log --format="commit %s" -L1,24:b.c -s >actual &&
144 test_cmp expect actual
147 test_expect_success '-p shows the default patch output' '
148 git log -L1,24:b.c >expect &&
149 git log -L1,24:b.c -p >actual &&
150 test_cmp expect actual
153 test_expect_success '--raw is forbidden' '
154 test_must_fail git log -L1,24:b.c --raw
157 test_expect_success 'setup for checking fancy rename following' '
158 git checkout --orphan moves-start &&
161 printf "%s\n" 12 13 14 15 b c d e >file-1 &&
162 printf "%s\n" 22 23 24 25 B C D E >file-2 &&
163 git add file-1 file-2 &&
165 git commit -m "Add file-1 and file-2" &&
166 oid_add_f1_f2=$(git rev-parse --short HEAD) &&
168 git checkout -b moves-main &&
169 printf "%s\n" 11 12 13 14 15 b c d e >file-1 &&
170 git commit -a -m "Modify file-1 on main" &&
171 oid_mod_f1_main=$(git rev-parse --short HEAD) &&
173 printf "%s\n" 21 22 23 24 25 B C D E >file-2 &&
174 git commit -a -m "Modify file-2 on main #1" &&
175 oid_mod_f2_main_1=$(git rev-parse --short HEAD) &&
177 git mv file-1 renamed-1 &&
178 git commit -m "Rename file-1 to renamed-1 on main" &&
180 printf "%s\n" 11 12 13 14 15 b c d e f >renamed-1 &&
181 git commit -a -m "Modify renamed-1 on main" &&
182 oid_mod_r1_main=$(git rev-parse --short HEAD) &&
184 printf "%s\n" 21 22 23 24 25 B C D E F >file-2 &&
185 git commit -a -m "Modify file-2 on main #2" &&
186 oid_mod_f2_main_2=$(git rev-parse --short HEAD) &&
188 git checkout -b moves-side moves-start &&
189 printf "%s\n" 12 13 14 15 16 b c d e >file-1 &&
190 git commit -a -m "Modify file-1 on side #1" &&
191 oid_mod_f1_side_1=$(git rev-parse --short HEAD) &&
193 printf "%s\n" 22 23 24 25 26 B C D E >file-2 &&
194 git commit -a -m "Modify file-2 on side" &&
195 oid_mod_f2_side=$(git rev-parse --short HEAD) &&
197 git mv file-2 renamed-2 &&
198 git commit -m "Rename file-2 to renamed-2 on side" &&
200 printf "%s\n" 12 13 14 15 16 a b c d e >file-1 &&
201 git commit -a -m "Modify file-1 on side #2" &&
202 oid_mod_f1_side_2=$(git rev-parse --short HEAD) &&
204 printf "%s\n" 22 23 24 25 26 A B C D E >renamed-2 &&
205 git commit -a -m "Modify renamed-2 on side" &&
206 oid_mod_r2_side=$(git rev-parse --short HEAD) &&
208 git checkout moves-main &&
209 git merge moves-side &&
210 oid_merge=$(git rev-parse --short HEAD)
213 test_expect_success 'fancy rename following #1' '
214 cat >expect <<-EOF &&
215 $oid_merge Merge branch '\''moves-side'\'' into moves-main
216 $oid_mod_f1_side_2 Modify file-1 on side #2
217 $oid_mod_f1_side_1 Modify file-1 on side #1
218 $oid_mod_r1_main Modify renamed-1 on main
219 $oid_mod_f1_main Modify file-1 on main
220 $oid_add_f1_f2 Add file-1 and file-2
222 git log -L1:renamed-1 --oneline --no-patch >actual &&
223 test_cmp expect actual
226 test_expect_success 'fancy rename following #2' '
227 cat >expect <<-EOF &&
228 $oid_merge Merge branch '\''moves-side'\'' into moves-main
229 $oid_mod_r2_side Modify renamed-2 on side
230 $oid_mod_f2_side Modify file-2 on side
231 $oid_mod_f2_main_2 Modify file-2 on main #2
232 $oid_mod_f2_main_1 Modify file-2 on main #1
233 $oid_add_f1_f2 Add file-1 and file-2
235 git log -L1:renamed-2 --oneline --no-patch >actual &&
236 test_cmp expect actual
239 # Create the following linear history, where each commit does what its
240 # subject line promises:
242 # * 66c6410 Modify func2() in file.c
243 # * 50834e5 Modify other-file
244 # * fe5851c Modify func1() in file.c
245 # * 8c7c7dd Add other-file
246 # * d5f4417 Add func1() and func2() in file.c
247 test_expect_success 'setup for checking line-log and parent oids' '
248 git checkout --orphan parent-oids &&
251 cat >file.c <<-\EOF &&
264 first_tick=$test_tick &&
265 git commit -m "Add func1() and func2() in file.c" &&
267 echo 1 >other-file &&
268 git add other-file &&
270 git commit -m "Add other-file" &&
272 sed -e "s/F1/F1 + 1/" file.c >tmp &&
274 git commit -a -m "Modify func1() in file.c" &&
276 echo 2 >other-file &&
277 git commit -a -m "Modify other-file" &&
279 sed -e "s/F2/F2 + 2/" file.c >tmp &&
281 git commit -a -m "Modify func2() in file.c" &&
283 head_oid=$(git rev-parse --short HEAD) &&
284 prev_oid=$(git rev-parse --short HEAD^) &&
285 root_oid=$(git rev-parse --short HEAD~4)
288 # Parent oid should be from immediate parent.
289 test_expect_success 'parent oids without parent rewriting' '
290 cat >expect <<-EOF &&
291 $head_oid $prev_oid Modify func2() in file.c
292 $root_oid Add func1() and func2() in file.c
294 git log --format="%h %p %s" --no-patch -L:func2:file.c >actual &&
295 test_cmp expect actual
298 # Parent oid should be from the most recent ancestor touching func2(),
299 # i.e. in this case from the root commit.
300 test_expect_success 'parent oids with parent rewriting' '
301 cat >expect <<-EOF &&
302 $head_oid $root_oid Modify func2() in file.c
303 $root_oid Add func1() and func2() in file.c
305 git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual &&
306 test_cmp expect actual
309 test_expect_success 'line-log with --before' '
310 echo $root_oid >expect &&
311 git log --format=%h --no-patch -L:func2:file.c --before=$first_tick >actual &&
312 test_cmp expect actual