]>
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)' ' | |
dfa5f53e | 7 | test_oid_init && |
12da1d1f TR |
8 | git fast-import < "$TEST_DIRECTORY"/t4211/history.export && |
9 | git reset --hard | |
10 | ' | |
11 | ||
d51c5274 TR |
12 | canned_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 |
19 | canned_test () { |
20 | canned_test_1 success "$@" | |
21 | } | |
22 | canned_test_failure () { | |
23 | canned_test_1 failure "$@" | |
24 | } | |
25 | ||
12da1d1f TR |
26 | test_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 | ||
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 | |
13b8f68c | 36 | canned_test "-L :f:a.c simple" simple-f-to-main |
12da1d1f TR |
37 | |
38 | canned_test "-L '/main/,/^}/:a.c' simple" simple-main | |
13b8f68c | 39 | canned_test "-L :main:a.c simple" simple-main-to-end |
12da1d1f TR |
40 | |
41 | canned_test "-L 1,+4:a.c simple" beginning-of-file | |
42 | ||
43 | canned_test "-L 20:a.c simple" end-of-file | |
44 | ||
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 | |
47 | ||
035ff398 | 48 | canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f |
31c61918 | 49 | canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main |
12da1d1f | 50 | |
20961886 | 51 | canned_test "-L 4,12:a.c -L :main:a.c simple" multiple |
215e76c7 | 52 | canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping |
20961886 | 53 | canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping |
3755b53a ES |
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 | |
20961886 | 56 | |
12da1d1f | 57 | test_bad_opts "-L" "switch.*requires a value" |
0269f968 MM |
58 | test_bad_opts "-L b.c" "argument not .start,end:file" |
59 | test_bad_opts "-L 1:" "argument not .start,end:file" | |
12da1d1f TR |
60 | test_bad_opts "-L 1:nonexistent" "There is no path" |
61 | test_bad_opts "-L 1:simple" "There is no path" | |
0269f968 | 62 | test_bad_opts "-L '/foo:b.c'" "argument not .start,end:file" |
12da1d1f | 63 | test_bad_opts "-L 1000:b.c" "has only.*lines" |
0269f968 | 64 | test_bad_opts "-L :b.c" "argument not .start,end:file" |
13b8f68c | 65 | test_bad_opts "-L :foo:b.c" "no match" |
12da1d1f | 66 | |
25fb8ee4 ES |
67 | test_expect_success '-L X (X == nlines)' ' |
68 | n=$(wc -l <b.c) && | |
69 | git log -L $n:b.c | |
70 | ' | |
71 | ||
63828b84 | 72 | test_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 | ||
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 | |
80 | ' | |
81 | ||
82 | test_expect_success '-L ,Y (Y == nlines)' ' | |
83 | n=$(printf "%d" $(wc -l <b.c)) && | |
84 | git log -L ,$n:b.c | |
85 | ' | |
86 | ||
87 | test_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 | ||
92 | test_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 |
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 | |
100 | ' | |
101 | ||
c1496934 JS |
102 | test_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 |
109 | test_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 |
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 | |
124 | ' | |
125 | ||
05314efa JK |
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 | |
130 | ' | |
131 | ||
132 | test_expect_success '--raw is forbidden' ' | |
133 | test_must_fail git log -L1,24:b.c --raw | |
134 | ' | |
135 | ||
a2bb801f SG |
136 | test_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 | ||
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 | |
200 | EOF | |
201 | git log -L1:renamed-1 --oneline --no-patch >actual && | |
202 | test_cmp expect actual | |
203 | ' | |
204 | ||
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 | |
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 | |
226 | test_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 && | |
243 | git commit -m "Add func1() and func2() in file.c" && | |
244 | ||
245 | echo 1 >other-file && | |
246 | git add other-file && | |
247 | git commit -m "Add other-file" && | |
248 | ||
249 | sed -e "s/F1/F1 + 1/" file.c >tmp && | |
250 | mv tmp file.c && | |
251 | git commit -a -m "Modify func1() in file.c" && | |
252 | ||
253 | echo 2 >other-file && | |
254 | git commit -a -m "Modify other-file" && | |
255 | ||
256 | sed -e "s/F2/F2 + 2/" file.c >tmp && | |
257 | mv tmp file.c && | |
258 | git commit -a -m "Modify func2() in file.c" && | |
259 | ||
260 | head_oid=$(git rev-parse --short HEAD) && | |
261 | prev_oid=$(git rev-parse --short HEAD^) && | |
262 | root_oid=$(git rev-parse --short HEAD~4) | |
263 | ' | |
264 | ||
265 | # Parent oid should be from immediate parent. | |
3cb9d2b6 | 266 | test_expect_success 'parent oids without parent rewriting' ' |
48da94ba SG |
267 | cat >expect <<-EOF && |
268 | $head_oid $prev_oid Modify func2() in file.c | |
269 | $root_oid Add func1() and func2() in file.c | |
270 | EOF | |
271 | git log --format="%h %p %s" --no-patch -L:func2:file.c >actual && | |
272 | test_cmp expect actual | |
273 | ' | |
274 | ||
275 | # Parent oid should be from the most recent ancestor touching func2(), | |
276 | # i.e. in this case from the root commit. | |
277 | test_expect_success 'parent oids with parent rewriting' ' | |
278 | cat >expect <<-EOF && | |
279 | $head_oid $root_oid Modify func2() in file.c | |
280 | $root_oid Add func1() and func2() in file.c | |
281 | EOF | |
282 | git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual && | |
283 | test_cmp expect actual | |
284 | ' | |
285 | ||
12da1d1f | 286 | test_done |