]>
Commit | Line | Data |
---|---|---|
12da1d1f TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='test log -L' | |
4 | . ./test-lib.sh | |
5 | ||
6 | test_expect_success 'setup (import history)' ' | |
7 | git fast-import < "$TEST_DIRECTORY"/t4211/history.export && | |
8 | git reset --hard | |
9 | ' | |
10 | ||
d51c5274 TR |
11 | canned_test_1 () { |
12 | test_expect_$1 "$2" " | |
13 | git log $2 >actual && | |
dfa5f53e | 14 | test_cmp \"\$TEST_DIRECTORY\"/t4211/$(test_oid algo)/expect.$3 actual |
12da1d1f TR |
15 | " |
16 | } | |
17 | ||
d51c5274 TR |
18 | canned_test () { |
19 | canned_test_1 success "$@" | |
20 | } | |
21 | canned_test_failure () { | |
22 | canned_test_1 failure "$@" | |
23 | } | |
24 | ||
12da1d1f TR |
25 | test_bad_opts () { |
26 | test_expect_success "invalid args: $1" " | |
27 | test_must_fail git log $1 2>errors && | |
9440b831 | 28 | test_i18ngrep '$2' errors |
12da1d1f TR |
29 | " |
30 | } | |
31 | ||
32 | canned_test "-L 4,12:a.c simple" simple-f | |
33 | canned_test "-L 4,+9:a.c simple" simple-f | |
34 | canned_test "-L '/long f/,/^}/:a.c' simple" simple-f | |
13b8f68c | 35 | canned_test "-L :f:a.c simple" simple-f-to-main |
12da1d1f TR |
36 | |
37 | canned_test "-L '/main/,/^}/:a.c' simple" simple-main | |
13b8f68c | 38 | canned_test "-L :main:a.c simple" simple-main-to-end |
12da1d1f TR |
39 | |
40 | canned_test "-L 1,+4:a.c simple" beginning-of-file | |
41 | ||
42 | canned_test "-L 20:a.c simple" end-of-file | |
43 | ||
44 | canned_test "-L '/long f/',/^}/:a.c -L /main/,/^}/:a.c simple" two-ranges | |
45 | canned_test "-L 24,+1:a.c simple" vanishes-early | |
46 | ||
035ff398 | 47 | canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f |
31c61918 | 48 | canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main |
12da1d1f | 49 | |
20961886 | 50 | canned_test "-L 4,12:a.c -L :main:a.c simple" multiple |
215e76c7 | 51 | canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping |
20961886 | 52 | canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping |
3755b53a ES |
53 | canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset |
54 | canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset | |
20961886 | 55 | |
12da1d1f | 56 | test_bad_opts "-L" "switch.*requires a value" |
0269f968 MM |
57 | test_bad_opts "-L b.c" "argument not .start,end:file" |
58 | test_bad_opts "-L 1:" "argument not .start,end:file" | |
12da1d1f TR |
59 | test_bad_opts "-L 1:nonexistent" "There is no path" |
60 | test_bad_opts "-L 1:simple" "There is no path" | |
0269f968 | 61 | test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file" |
12da1d1f | 62 | test_bad_opts "-L 1000:b.c" "has only.*lines" |
0269f968 | 63 | test_bad_opts "-L :b.c" "argument not .start,end:file" |
13b8f68c | 64 | test_bad_opts "-L :foo:b.c" "no match" |
12da1d1f | 65 | |
25fb8ee4 ES |
66 | test_expect_success '-L X (X == nlines)' ' |
67 | n=$(wc -l <b.c) && | |
68 | git log -L $n:b.c | |
69 | ' | |
70 | ||
63828b84 | 71 | test_expect_success '-L X (X == nlines + 1)' ' |
25fb8ee4 ES |
72 | n=$(expr $(wc -l <b.c) + 1) && |
73 | test_must_fail git log -L $n:b.c | |
74 | ' | |
75 | ||
76 | test_expect_success '-L X (X == nlines + 2)' ' | |
77 | n=$(expr $(wc -l <b.c) + 2) && | |
78 | test_must_fail git log -L $n:b.c | |
79 | ' | |
80 | ||
81 | test_expect_success '-L ,Y (Y == nlines)' ' | |
82 | n=$(printf "%d" $(wc -l <b.c)) && | |
83 | git log -L ,$n:b.c | |
84 | ' | |
85 | ||
86 | test_expect_success '-L ,Y (Y == nlines + 1)' ' | |
87 | n=$(expr $(wc -l <b.c) + 1) && | |
7f81c00f | 88 | git log -L ,$n:b.c |
25fb8ee4 ES |
89 | ' |
90 | ||
91 | test_expect_success '-L ,Y (Y == nlines + 2)' ' | |
92 | n=$(expr $(wc -l <b.c) + 2) && | |
7f81c00f | 93 | git log -L ,$n:b.c |
25fb8ee4 ES |
94 | ' |
95 | ||
a8787c5c TM |
96 | test_expect_success '-L with --first-parent and a merge' ' |
97 | git checkout parallel-change && | |
98 | git log --first-parent -L 1,1:b.c | |
99 | ' | |
100 | ||
c1496934 JS |
101 | test_expect_success '-L with --output' ' |
102 | git checkout parallel-change && | |
103 | git log --output=log -L :main:b.c >output && | |
f0dc593a | 104 | test_must_be_empty output && |
c1496934 JS |
105 | test_line_count = 70 log |
106 | ' | |
107 | ||
aaae0bf7 AX |
108 | test_expect_success 'range_set_union' ' |
109 | test_seq 500 > c.c && | |
110 | git add c.c && | |
111 | git commit -m "many lines" && | |
112 | test_seq 1000 > c.c && | |
113 | git add c.c && | |
114 | git commit -m "modify many lines" && | |
115 | git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done) | |
116 | ' | |
117 | ||
9f607cd0 JK |
118 | test_expect_success '-s shows only line-log commits' ' |
119 | git log --format="commit %s" -L1,24:b.c >expect.raw && | |
120 | grep ^commit expect.raw >expect && | |
121 | git log --format="commit %s" -L1,24:b.c -s >actual && | |
122 | test_cmp expect actual | |
123 | ' | |
124 | ||
05314efa JK |
125 | test_expect_success '-p shows the default patch output' ' |
126 | git log -L1,24:b.c >expect && | |
127 | git log -L1,24:b.c -p >actual && | |
128 | test_cmp expect actual | |
129 | ' | |
130 | ||
131 | test_expect_success '--raw is forbidden' ' | |
132 | test_must_fail git log -L1,24:b.c --raw | |
133 | ' | |
134 | ||
a2bb801f SG |
135 | test_expect_success 'setup for checking fancy rename following' ' |
136 | git checkout --orphan moves-start && | |
137 | git reset --hard && | |
138 | ||
139 | printf "%s\n" 12 13 14 15 b c d e >file-1 && | |
140 | printf "%s\n" 22 23 24 25 B C D E >file-2 && | |
141 | git add file-1 file-2 && | |
142 | test_tick && | |
143 | git commit -m "Add file-1 and file-2" && | |
144 | oid_add_f1_f2=$(git rev-parse --short HEAD) && | |
145 | ||
146 | git checkout -b moves-main && | |
147 | printf "%s\n" 11 12 13 14 15 b c d e >file-1 && | |
148 | git commit -a -m "Modify file-1 on main" && | |
149 | oid_mod_f1_main=$(git rev-parse --short HEAD) && | |
150 | ||
151 | printf "%s\n" 21 22 23 24 25 B C D E >file-2 && | |
152 | git commit -a -m "Modify file-2 on main #1" && | |
153 | oid_mod_f2_main_1=$(git rev-parse --short HEAD) && | |
154 | ||
155 | git mv file-1 renamed-1 && | |
156 | git commit -m "Rename file-1 to renamed-1 on main" && | |
157 | ||
158 | printf "%s\n" 11 12 13 14 15 b c d e f >renamed-1 && | |
159 | git commit -a -m "Modify renamed-1 on main" && | |
160 | oid_mod_r1_main=$(git rev-parse --short HEAD) && | |
161 | ||
162 | printf "%s\n" 21 22 23 24 25 B C D E F >file-2 && | |
163 | git commit -a -m "Modify file-2 on main #2" && | |
164 | oid_mod_f2_main_2=$(git rev-parse --short HEAD) && | |
165 | ||
166 | git checkout -b moves-side moves-start && | |
167 | printf "%s\n" 12 13 14 15 16 b c d e >file-1 && | |
168 | git commit -a -m "Modify file-1 on side #1" && | |
169 | oid_mod_f1_side_1=$(git rev-parse --short HEAD) && | |
170 | ||
171 | printf "%s\n" 22 23 24 25 26 B C D E >file-2 && | |
172 | git commit -a -m "Modify file-2 on side" && | |
173 | oid_mod_f2_side=$(git rev-parse --short HEAD) && | |
174 | ||
175 | git mv file-2 renamed-2 && | |
176 | git commit -m "Rename file-2 to renamed-2 on side" && | |
177 | ||
178 | printf "%s\n" 12 13 14 15 16 a b c d e >file-1 && | |
179 | git commit -a -m "Modify file-1 on side #2" && | |
180 | oid_mod_f1_side_2=$(git rev-parse --short HEAD) && | |
181 | ||
182 | printf "%s\n" 22 23 24 25 26 A B C D E >renamed-2 && | |
183 | git commit -a -m "Modify renamed-2 on side" && | |
184 | oid_mod_r2_side=$(git rev-parse --short HEAD) && | |
185 | ||
186 | git checkout moves-main && | |
187 | git merge moves-side && | |
188 | oid_merge=$(git rev-parse --short HEAD) | |
189 | ' | |
190 | ||
191 | test_expect_success 'fancy rename following #1' ' | |
192 | cat >expect <<-EOF && | |
193 | $oid_merge Merge branch '\''moves-side'\'' into moves-main | |
194 | $oid_mod_f1_side_2 Modify file-1 on side #2 | |
195 | $oid_mod_f1_side_1 Modify file-1 on side #1 | |
196 | $oid_mod_r1_main Modify renamed-1 on main | |
197 | $oid_mod_f1_main Modify file-1 on main | |
198 | $oid_add_f1_f2 Add file-1 and file-2 | |
199 | EOF | |
200 | git log -L1:renamed-1 --oneline --no-patch >actual && | |
201 | test_cmp expect actual | |
202 | ' | |
203 | ||
204 | test_expect_success 'fancy rename following #2' ' | |
205 | cat >expect <<-EOF && | |
206 | $oid_merge Merge branch '\''moves-side'\'' into moves-main | |
207 | $oid_mod_r2_side Modify renamed-2 on side | |
208 | $oid_mod_f2_side Modify file-2 on side | |
209 | $oid_mod_f2_main_2 Modify file-2 on main #2 | |
210 | $oid_mod_f2_main_1 Modify file-2 on main #1 | |
211 | $oid_add_f1_f2 Add file-1 and file-2 | |
212 | EOF | |
213 | git log -L1:renamed-2 --oneline --no-patch >actual && | |
214 | test_cmp expect actual | |
215 | ' | |
216 | ||
48da94ba SG |
217 | # Create the following linear history, where each commit does what its |
218 | # subject line promises: | |
219 | # | |
220 | # * 66c6410 Modify func2() in file.c | |
221 | # * 50834e5 Modify other-file | |
222 | # * fe5851c Modify func1() in file.c | |
223 | # * 8c7c7dd Add other-file | |
224 | # * d5f4417 Add func1() and func2() in file.c | |
225 | test_expect_success 'setup for checking line-log and parent oids' ' | |
226 | git checkout --orphan parent-oids && | |
227 | git reset --hard && | |
228 | ||
229 | cat >file.c <<-\EOF && | |
230 | int func1() | |
231 | { | |
232 | return F1; | |
233 | } | |
234 | ||
235 | int func2() | |
236 | { | |
237 | return F2; | |
238 | } | |
239 | EOF | |
240 | git add file.c && | |
241 | test_tick && | |
01faa91c | 242 | first_tick=$test_tick && |
48da94ba SG |
243 | git commit -m "Add func1() and func2() in file.c" && |
244 | ||
245 | echo 1 >other-file && | |
246 | git add other-file && | |
01faa91c | 247 | test_tick && |
48da94ba SG |
248 | git commit -m "Add other-file" && |
249 | ||
250 | sed -e "s/F1/F1 + 1/" file.c >tmp && | |
251 | mv tmp file.c && | |
252 | git commit -a -m "Modify func1() in file.c" && | |
253 | ||
254 | echo 2 >other-file && | |
255 | git commit -a -m "Modify other-file" && | |
256 | ||
257 | sed -e "s/F2/F2 + 2/" file.c >tmp && | |
258 | mv tmp file.c && | |
259 | git commit -a -m "Modify func2() in file.c" && | |
260 | ||
261 | head_oid=$(git rev-parse --short HEAD) && | |
262 | prev_oid=$(git rev-parse --short HEAD^) && | |
263 | root_oid=$(git rev-parse --short HEAD~4) | |
264 | ' | |
265 | ||
266 | # Parent oid should be from immediate parent. | |
3cb9d2b6 | 267 | test_expect_success 'parent oids without parent rewriting' ' |
48da94ba SG |
268 | cat >expect <<-EOF && |
269 | $head_oid $prev_oid Modify func2() in file.c | |
270 | $root_oid Add func1() and func2() in file.c | |
271 | EOF | |
272 | git log --format="%h %p %s" --no-patch -L:func2:file.c >actual && | |
273 | test_cmp expect actual | |
274 | ' | |
275 | ||
276 | # Parent oid should be from the most recent ancestor touching func2(), | |
277 | # i.e. in this case from the root commit. | |
278 | test_expect_success 'parent oids with parent rewriting' ' | |
279 | cat >expect <<-EOF && | |
280 | $head_oid $root_oid Modify func2() in file.c | |
281 | $root_oid Add func1() and func2() in file.c | |
282 | EOF | |
283 | git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual && | |
284 | test_cmp expect actual | |
285 | ' | |
286 | ||
01faa91c RS |
287 | test_expect_success 'line-log with --before' ' |
288 | echo $root_oid >expect && | |
289 | git log --format=%h --no-patch -L:func2:file.c --before=$first_tick >actual && | |
290 | test_cmp expect actual | |
291 | ' | |
292 | ||
12da1d1f | 293 | test_done |