]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4211-line-log.sh
checkout -p: handle tree arguments correctly again
[thirdparty/git.git] / t / t4211-line-log.sh
CommitLineData
12da1d1f
TR
1#!/bin/sh
2
3test_description='test log -L'
4. ./test-lib.sh
5
6test_expect_success 'setup (import history)' '
dfa5f53e 7 test_oid_init &&
12da1d1f
TR
8 git fast-import < "$TEST_DIRECTORY"/t4211/history.export &&
9 git reset --hard
10'
11
d51c5274
TR
12canned_test_1 () {
13 test_expect_$1 "$2" "
14 git log $2 >actual &&
dfa5f53e 15 test_cmp \"\$TEST_DIRECTORY\"/t4211/$(test_oid algo)/expect.$3 actual
12da1d1f
TR
16 "
17}
18
d51c5274
TR
19canned_test () {
20 canned_test_1 success "$@"
21}
22canned_test_failure () {
23 canned_test_1 failure "$@"
24}
25
12da1d1f
TR
26test_bad_opts () {
27 test_expect_success "invalid args: $1" "
28 test_must_fail git log $1 2>errors &&
9440b831 29 test_i18ngrep '$2' errors
12da1d1f
TR
30 "
31}
32
33canned_test "-L 4,12:a.c simple" simple-f
34canned_test "-L 4,+9:a.c simple" simple-f
35canned_test "-L '/long f/,/^}/:a.c' simple" simple-f
13b8f68c 36canned_test "-L :f:a.c simple" simple-f-to-main
12da1d1f
TR
37
38canned_test "-L '/main/,/^}/:a.c' simple" simple-main
13b8f68c 39canned_test "-L :main:a.c simple" simple-main-to-end
12da1d1f
TR
40
41canned_test "-L 1,+4:a.c simple" beginning-of-file
42
43canned_test "-L 20:a.c simple" end-of-file
44
45canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges
46canned_test "-L 24,+1:a.c simple" vanishes-early
47
035ff398 48canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f
31c61918 49canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
12da1d1f 50
20961886 51canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
215e76c7 52canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping
20961886 53canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
3755b53a
ES
54canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
55canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
20961886 56
12da1d1f 57test_bad_opts "-L" "switch.*requires a value"
0269f968
MM
58test_bad_opts "-L b.c" "argument not .start,end:file"
59test_bad_opts "-L 1:" "argument not .start,end:file"
12da1d1f
TR
60test_bad_opts "-L 1:nonexistent" "There is no path"
61test_bad_opts "-L 1:simple" "There is no path"
0269f968 62test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file"
12da1d1f 63test_bad_opts "-L 1000:b.c" "has only.*lines"
0269f968 64test_bad_opts "-L :b.c" "argument not .start,end:file"
13b8f68c 65test_bad_opts "-L :foo:b.c" "no match"
12da1d1f 66
25fb8ee4
ES
67test_expect_success '-L X (X == nlines)' '
68 n=$(wc -l <b.c) &&
69 git log -L $n:b.c
70'
71
63828b84 72test_expect_success '-L X (X == nlines + 1)' '
25fb8ee4
ES
73 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) &&
7f81c00f 89 git log -L ,$n:b.c
25fb8ee4
ES
90'
91
92test_expect_success '-L ,Y (Y == nlines + 2)' '
93 n=$(expr $(wc -l <b.c) + 2) &&
7f81c00f 94 git log -L ,$n:b.c
25fb8ee4
ES
95'
96
a8787c5c
TM
97test_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
c1496934
JS
102test_expect_success '-L with --output' '
103 git checkout parallel-change &&
104 git log --output=log -L :main:b.c >output &&
f0dc593a 105 test_must_be_empty output &&
c1496934
JS
106 test_line_count = 70 log
107'
108
aaae0bf7
AX
109test_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
9f607cd0
JK
119test_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
124'
125
05314efa
JK
126test_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
130'
131
132test_expect_success '--raw is forbidden' '
133 test_must_fail git log -L1,24:b.c --raw
134'
135
a2bb801f
SG
136test_expect_success 'setup for checking fancy rename following' '
137 git checkout --orphan moves-start &&
138 git reset --hard &&
139
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 &&
143 test_tick &&
144 git commit -m "Add file-1 and file-2" &&
145 oid_add_f1_f2=$(git rev-parse --short HEAD) &&
146
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) &&
151
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) &&
155
156 git mv file-1 renamed-1 &&
157 git commit -m "Rename file-1 to renamed-1 on main" &&
158
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) &&
162
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) &&
166
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) &&
171
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) &&
175
176 git mv file-2 renamed-2 &&
177 git commit -m "Rename file-2 to renamed-2 on side" &&
178
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) &&
182
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) &&
186
187 git checkout moves-main &&
188 git merge moves-side &&
189 oid_merge=$(git rev-parse --short HEAD)
190'
191
192test_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
200 EOF
201 git log -L1:renamed-1 --oneline --no-patch >actual &&
202 test_cmp expect actual
203'
204
205test_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
213 EOF
214 git log -L1:renamed-2 --oneline --no-patch >actual &&
215 test_cmp expect actual
216'
217
48da94ba
SG
218# Create the following linear history, where each commit does what its
219# subject line promises:
220#
221# * 66c6410 Modify func2() in file.c
222# * 50834e5 Modify other-file
223# * fe5851c Modify func1() in file.c
224# * 8c7c7dd Add other-file
225# * d5f4417 Add func1() and func2() in file.c
226test_expect_success 'setup for checking line-log and parent oids' '
227 git checkout --orphan parent-oids &&
228 git reset --hard &&
229
230 cat >file.c <<-\EOF &&
231 int func1()
232 {
233 return F1;
234 }
235
236 int func2()
237 {
238 return F2;
239 }
240 EOF
241 git add file.c &&
242 test_tick &&
01faa91c 243 first_tick=$test_tick &&
48da94ba
SG
244 git commit -m "Add func1() and func2() in file.c" &&
245
246 echo 1 >other-file &&
247 git add other-file &&
01faa91c 248 test_tick &&
48da94ba
SG
249 git commit -m "Add other-file" &&
250
251 sed -e "s/F1/F1 + 1/" file.c >tmp &&
252 mv tmp file.c &&
253 git commit -a -m "Modify func1() in file.c" &&
254
255 echo 2 >other-file &&
256 git commit -a -m "Modify other-file" &&
257
258 sed -e "s/F2/F2 + 2/" file.c >tmp &&
259 mv tmp file.c &&
260 git commit -a -m "Modify func2() in file.c" &&
261
262 head_oid=$(git rev-parse --short HEAD) &&
263 prev_oid=$(git rev-parse --short HEAD^) &&
264 root_oid=$(git rev-parse --short HEAD~4)
265'
266
267# Parent oid should be from immediate parent.
3cb9d2b6 268test_expect_success 'parent oids without parent rewriting' '
48da94ba
SG
269 cat >expect <<-EOF &&
270 $head_oid $prev_oid Modify func2() in file.c
271 $root_oid Add func1() and func2() in file.c
272 EOF
273 git log --format="%h %p %s" --no-patch -L:func2:file.c >actual &&
274 test_cmp expect actual
275'
276
277# Parent oid should be from the most recent ancestor touching func2(),
278# i.e. in this case from the root commit.
279test_expect_success 'parent oids with parent rewriting' '
280 cat >expect <<-EOF &&
281 $head_oid $root_oid Modify func2() in file.c
282 $root_oid Add func1() and func2() in file.c
283 EOF
284 git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual &&
285 test_cmp expect actual
286'
287
01faa91c
RS
288test_expect_success 'line-log with --before' '
289 echo $root_oid >expect &&
290 git log --format=%h --no-patch -L:func2:file.c --before=$first_tick >actual &&
291 test_cmp expect actual
292'
293
12da1d1f 294test_done