View Javadoc
1   /*
2    * Copyright (C) 2011, Christian Halstrick <christian.halstrick@sap.com>
3    * Copyright (C) 2011, Philipp Thun <philipp.thun@sap.com>
4    * and other copyright owners as documented in the project's IP log.
5    *
6    * This program and the accompanying materials are made available
7    * under the terms of the Eclipse Distribution License v1.0 which
8    * accompanies this distribution, is reproduced below, and is
9    * available at http://www.eclipse.org/org/documents/edl-v10.php
10   *
11   * All rights reserved.
12   *
13   * Redistribution and use in source and binary forms, with or
14   * without modification, are permitted provided that the following
15   * conditions are met:
16   *
17   * - Redistributions of source code must retain the above copyright
18   *   notice, this list of conditions and the following disclaimer.
19   *
20   * - Redistributions in binary form must reproduce the above
21   *   copyright notice, this list of conditions and the following
22   *   disclaimer in the documentation and/or other materials provided
23   *   with the distribution.
24   *
25   * - Neither the name of the Eclipse Foundation, Inc. nor the
26   *   names of its contributors may be used to endorse or promote
27   *   products derived from this software without specific prior
28   *   written permission.
29   *
30   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
31   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
32   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
42   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43   */
44  package org.eclipse.jgit.api;
45  
46  import static org.junit.Assert.assertEquals;
47  import static org.junit.Assert.assertNotNull;
48  import static org.junit.Assert.assertTrue;
49  
50  import java.io.File;
51  import java.io.IOException;
52  
53  import org.eclipse.jgit.api.errors.JGitInternalException;
54  import org.eclipse.jgit.junit.RepositoryTestCase;
55  import org.eclipse.jgit.lib.Constants;
56  import org.eclipse.jgit.lib.ObjectId;
57  import org.eclipse.jgit.lib.Repository;
58  import org.eclipse.jgit.revwalk.RevWalk;
59  import org.eclipse.jgit.treewalk.TreeWalk;
60  import org.junit.Test;
61  
62  /**
63   * Testing the 'commit only' option:
64   *
65   * I. A single file (f1.txt) specified as part of the --only/ -o option can have
66   * one of the following (14) states:
67   *
68   * <pre>
69   *        |                          | expected result
70   * ---------------------------------------------------------------------
71   *        | HEAD  DirCache  Worktree | HEAD  DirCache
72   * ---------------------------------------------------------------------
73   *  f1_1  |  -       -       c       |                =&gt; e: path unknown
74   *  f1_2  |  -       c       -       |                =&gt; no changes
75   *  f1_3  |  c       -       -       |  -       -
76   *  f1_4  |  -       c       c       |  c       c
77   *  f1_5  |  c       c       -       |  -       -
78   *  f1_6  |  c       -       c       |                =&gt; no changes
79   *  f1_7  |  c       c       c       |                =&gt; no changes
80   * ---------------------------------------------------------------------
81   *  f1_8  |  -       c       c'      |  c'      c'
82   *  f1_9  |  c       -       c'      |  c'      c'
83   * f1_10  |  c       c'      -       |  -       -
84   * f1_11  |  c       c       c'      |  c'      c'
85   * f1_12  |  c       c'      c       |                =&gt; no changes
86   * f1_13  |  c       c'      c'      |  c'      c'
87   * ---------------------------------------------------------------------
88   * f1_14  |  c       c'      c''     |  c''     c''
89   * </pre>
90   *
91   * II. Scenarios that do not end with a successful commit (1, 2, 6, 7, 12) have
92   * to be tested with a second file (f2.txt) specified that would lead to a
93   * successful commit, if it were executed separately (e.g. scenario 14).
94   *
95   * <pre>
96   *              |                          | expected result
97   * ---------------------------------------------------------------------------
98   *              | HEAD  DirCache  Worktree | HEAD  DirCache
99   * ---------------------------------------------------------------------------
100  *  f1_1_f2_14  |  -       -       c       |                =&gt; e: path unknown
101  *  f1_2_f2_14  |  -       c       -       |  -       -
102  *  f1_6_f2_14  |  c       -       c       |  c       c
103  *  f1_7_f2_14  |  c       c       c       |  c       c
104  * ---------------------------------------------------------------------------
105  * f1_12_f2_14  |  c       c'      c       |  c       c
106  * </pre>
107  *
108  * III. All scenarios (1-14, I-II) have to be tested with different repository
109  * states, to check that the --only/ -o option does not change existing content
110  * (HEAD and DirCache). The following states for a file (f3.txt) not specified
111  * shall be tested:
112  *
113  * <pre>
114  *       | HEAD  DirCache
115  * --------------------
116  *  *_a  |  -       -
117  *  *_b  |  -       c
118  *  *_c  |  c       c
119  *  *_d  |  c       -
120  * --------------------
121  *  *_e  |  c       c'
122  * </pre>
123  **/
124 public class CommitOnlyTest extends RepositoryTestCase {
125 	private static final String F1 = "f1.txt";
126 
127 	private static final String F2 = "f2.txt";
128 
129 	private static final String F3 = "f3.txt";
130 
131 	private static final String MSG = "commit";
132 
133 	private static int A = 0;
134 
135 	private static int B = 1;
136 
137 	private static int C = 2;
138 
139 	private static int D = 3;
140 
141 	private static int E = 4;
142 
143 	@Test
144 	public void testOnlyOption_f1_1_a() throws Exception {
145 		final Git git = new Git(db);
146 		prepare_f3(git, A);
147 		prepare_f1_1(git);
148 		executeAndCheck_f1_1(git, A);
149 	}
150 
151 	@Test
152 	public void testOnlyOption_f1_1_b() throws Exception {
153 		final Git git = new Git(db);
154 		prepare_f3(git, B);
155 		prepare_f1_1(git);
156 		executeAndCheck_f1_1(git, B);
157 	}
158 
159 	@Test
160 	public void testOnlyOption_f1_1_c() throws Exception {
161 		final Git git = new Git(db);
162 		prepare_f3(git, C);
163 		prepare_f1_1(git);
164 		executeAndCheck_f1_1(git, C);
165 	}
166 
167 	@Test
168 	public void testOnlyOption_f1_1_d() throws Exception {
169 		final Git git = new Git(db);
170 		prepare_f3(git, D);
171 		prepare_f1_1(git);
172 		executeAndCheck_f1_1(git, D);
173 	}
174 
175 	@Test
176 	public void testOnlyOption_f1_1_e() throws Exception {
177 		final Git git = new Git(db);
178 		prepare_f3(git, E);
179 		prepare_f1_1(git);
180 		executeAndCheck_f1_1(git, E);
181 	}
182 
183 	@Test
184 	public void testOnlyOption_f1_1_f2_14_a() throws Exception {
185 		final Git git = new Git(db);
186 		prepare_f3_f2_14(git, A);
187 		prepare_f1_1(git);
188 		executeAndCheck_f1_1_f2_f14(git, A);
189 	}
190 
191 	@Test
192 	public void testOnlyOption_f1_1_f2_14_b() throws Exception {
193 		final Git git = new Git(db);
194 		prepare_f3_f2_14(git, B);
195 		prepare_f1_1(git);
196 		executeAndCheck_f1_1_f2_f14(git, B);
197 	}
198 
199 	@Test
200 	public void testOnlyOption_f1_1_f2_14_c() throws Exception {
201 		final Git git = new Git(db);
202 		prepare_f3_f2_14(git, C);
203 		prepare_f1_1(git);
204 		executeAndCheck_f1_1_f2_f14(git, C);
205 	}
206 
207 	@Test
208 	public void testOnlyOption_f1_1_f2_14_d() throws Exception {
209 		final Git git = new Git(db);
210 		prepare_f3_f2_14(git, D);
211 		prepare_f1_1(git);
212 		executeAndCheck_f1_1_f2_f14(git, D);
213 	}
214 
215 	@Test
216 	public void testOnlyOption_f1_1_f2_14_e() throws Exception {
217 		final Git git = new Git(db);
218 		prepare_f3_f2_14(git, E);
219 		prepare_f1_1(git);
220 		executeAndCheck_f1_1_f2_f14(git, E);
221 	}
222 
223 	@Test
224 	public void testOnlyOption_f1_2_a() throws Exception {
225 		final Git git = new Git(db);
226 		prepare_f3(git, A);
227 		prepare_f1_2(git);
228 		executeAndCheck_f1_2(git, A);
229 	}
230 
231 	@Test
232 	public void testOnlyOption_f1_2_b() throws Exception {
233 		final Git git = new Git(db);
234 		prepare_f3(git, B);
235 		prepare_f1_2(git);
236 		executeAndCheck_f1_2(git, B);
237 	}
238 
239 	@Test
240 	public void testOnlyOption_f1_2_c() throws Exception {
241 		final Git git = new Git(db);
242 		prepare_f3(git, C);
243 		prepare_f1_2(git);
244 		executeAndCheck_f1_2(git, C);
245 	}
246 
247 	@Test
248 	public void testOnlyOption_f1_2_d() throws Exception {
249 		final Git git = new Git(db);
250 		prepare_f3(git, D);
251 		prepare_f1_2(git);
252 		executeAndCheck_f1_2(git, D);
253 	}
254 
255 	@Test
256 	public void testOnlyOption_f1_2_e() throws Exception {
257 		final Git git = new Git(db);
258 		prepare_f3(git, E);
259 		prepare_f1_2(git);
260 		executeAndCheck_f1_2(git, E);
261 	}
262 
263 	@Test
264 	public void testOnlyOption_f1_2_f2_14_a() throws Exception {
265 		final Git git = new Git(db);
266 		prepare_f3_f2_14(git, A);
267 		prepare_f1_2(git);
268 		executeAndCheck_f1_2_f2_f14(git, A);
269 	}
270 
271 	@Test
272 	public void testOnlyOption_f1_2_f2_14_b() throws Exception {
273 		final Git git = new Git(db);
274 		prepare_f3_f2_14(git, B);
275 		prepare_f1_2(git);
276 		executeAndCheck_f1_2_f2_f14(git, B);
277 	}
278 
279 	@Test
280 	public void testOnlyOption_f1_2_f2_14_c() throws Exception {
281 		final Git git = new Git(db);
282 		prepare_f3_f2_14(git, C);
283 		prepare_f1_2(git);
284 		executeAndCheck_f1_2_f2_f14(git, C);
285 	}
286 
287 	@Test
288 	public void testOnlyOption_f1_2_f2_14_d() throws Exception {
289 		final Git git = new Git(db);
290 		prepare_f3_f2_14(git, D);
291 		prepare_f1_2(git);
292 		executeAndCheck_f1_2_f2_f14(git, D);
293 	}
294 
295 	@Test
296 	public void testOnlyOption_f1_2_f2_14_e() throws Exception {
297 		final Git git = new Git(db);
298 		prepare_f3_f2_14(git, E);
299 		prepare_f1_2(git);
300 		executeAndCheck_f1_2_f2_f14(git, E);
301 	}
302 
303 	@Test
304 	public void testOnlyOption_f1_3_a() throws Exception {
305 		final Git git = new Git(db);
306 		prepare_f3(git, A);
307 		prepare_f1_3(git);
308 		executeAndCheck_f1_3(git, A);
309 	}
310 
311 	@Test
312 	public void testOnlyOption_f1_3_b() throws Exception {
313 		final Git git = new Git(db);
314 		prepare_f3(git, B);
315 		prepare_f1_3(git);
316 		executeAndCheck_f1_3(git, B);
317 	}
318 
319 	@Test
320 	public void testOnlyOption_f1_3_c() throws Exception {
321 		final Git git = new Git(db);
322 		prepare_f3(git, C);
323 		prepare_f1_3(git);
324 		executeAndCheck_f1_3(git, C);
325 	}
326 
327 	@Test
328 	public void testOnlyOption_f1_3_d() throws Exception {
329 		final Git git = new Git(db);
330 		prepare_f3(git, D);
331 		prepare_f1_3(git);
332 		executeAndCheck_f1_3(git, D);
333 	}
334 
335 	@Test
336 	public void testOnlyOption_f1_3_e() throws Exception {
337 		final Git git = new Git(db);
338 		prepare_f3(git, E);
339 		prepare_f1_3(git);
340 		executeAndCheck_f1_3(git, E);
341 	}
342 
343 	@Test
344 	public void testOnlyOption_f1_4_a() throws Exception {
345 		final Git git = new Git(db);
346 		prepare_f3(git, A);
347 		prepare_f1_4(git);
348 		executeAndCheck_f1_4(git, A);
349 	}
350 
351 	@Test
352 	public void testOnlyOption_f1_4_b() throws Exception {
353 		final Git git = new Git(db);
354 		prepare_f3(git, B);
355 		prepare_f1_4(git);
356 		executeAndCheck_f1_4(git, B);
357 	}
358 
359 	@Test
360 	public void testOnlyOption_f1_4_c() throws Exception {
361 		final Git git = new Git(db);
362 		prepare_f3(git, C);
363 		prepare_f1_4(git);
364 		executeAndCheck_f1_4(git, C);
365 	}
366 
367 	@Test
368 	public void testOnlyOption_f1_4_d() throws Exception {
369 		final Git git = new Git(db);
370 		prepare_f3(git, D);
371 		prepare_f1_4(git);
372 		executeAndCheck_f1_4(git, D);
373 	}
374 
375 	@Test
376 	public void testOnlyOption_f1_4_e() throws Exception {
377 		final Git git = new Git(db);
378 		prepare_f3(git, E);
379 		prepare_f1_4(git);
380 		executeAndCheck_f1_4(git, E);
381 	}
382 
383 	@Test
384 	public void testOnlyOption_f1_5_a() throws Exception {
385 		final Git git = new Git(db);
386 		prepare_f3(git, A);
387 		prepare_f1_5(git);
388 		executeAndCheck_f1_5(git, A);
389 	}
390 
391 	@Test
392 	public void testOnlyOption_f1_5_b() throws Exception {
393 		final Git git = new Git(db);
394 		prepare_f3(git, B);
395 		prepare_f1_5(git);
396 		executeAndCheck_f1_5(git, B);
397 	}
398 
399 	@Test
400 	public void testOnlyOption_f1_5_c() throws Exception {
401 		final Git git = new Git(db);
402 		prepare_f3(git, C);
403 		prepare_f1_5(git);
404 		executeAndCheck_f1_5(git, C);
405 	}
406 
407 	@Test
408 	public void testOnlyOption_f1_5_d() throws Exception {
409 		final Git git = new Git(db);
410 		prepare_f3(git, D);
411 		prepare_f1_5(git);
412 		executeAndCheck_f1_5(git, D);
413 	}
414 
415 	@Test
416 	public void testOnlyOption_f1_5_e() throws Exception {
417 		final Git git = new Git(db);
418 		prepare_f3(git, E);
419 		prepare_f1_5(git);
420 		executeAndCheck_f1_5(git, E);
421 	}
422 
423 	@Test
424 	public void testOnlyOption_f1_6_a() throws Exception {
425 		final Git git = new Git(db);
426 		prepare_f3(git, A);
427 		prepare_f1_6(git);
428 		executeAndCheck_f1_6(git, A);
429 	}
430 
431 	@Test
432 	public void testOnlyOption_f1_6_b() throws Exception {
433 		final Git git = new Git(db);
434 		prepare_f3(git, B);
435 		prepare_f1_6(git);
436 		executeAndCheck_f1_6(git, B);
437 	}
438 
439 	@Test
440 	public void testOnlyOption_f1_6_c() throws Exception {
441 		final Git git = new Git(db);
442 		prepare_f3(git, C);
443 		prepare_f1_6(git);
444 		executeAndCheck_f1_6(git, C);
445 	}
446 
447 	@Test
448 	public void testOnlyOption_f1_6_d() throws Exception {
449 		final Git git = new Git(db);
450 		prepare_f3(git, D);
451 		prepare_f1_6(git);
452 		executeAndCheck_f1_6(git, D);
453 	}
454 
455 	@Test
456 	public void testOnlyOption_f1_6_e() throws Exception {
457 		final Git git = new Git(db);
458 		prepare_f3(git, E);
459 		prepare_f1_6(git);
460 		executeAndCheck_f1_6(git, E);
461 	}
462 
463 	@Test
464 	public void testOnlyOption_f1_6_f2_14_a() throws Exception {
465 		final Git git = new Git(db);
466 		prepare_f3_f2_14(git, A);
467 		prepare_f1_6(git);
468 		executeAndCheck_f1_6_f2_14(git, A);
469 	}
470 
471 	@Test
472 	public void testOnlyOption_f1_6_f2_14_b() throws Exception {
473 		final Git git = new Git(db);
474 		prepare_f3_f2_14(git, B);
475 		prepare_f1_6(git);
476 		executeAndCheck_f1_6_f2_14(git, B);
477 	}
478 
479 	@Test
480 	public void testOnlyOption_f1_6_f2_14_c() throws Exception {
481 		final Git git = new Git(db);
482 		prepare_f3_f2_14(git, C);
483 		prepare_f1_6(git);
484 		executeAndCheck_f1_6_f2_14(git, C);
485 	}
486 
487 	@Test
488 	public void testOnlyOption_f1_6_f2_14_d() throws Exception {
489 		final Git git = new Git(db);
490 		prepare_f3_f2_14(git, D);
491 		prepare_f1_6(git);
492 		executeAndCheck_f1_6_f2_14(git, D);
493 	}
494 
495 	@Test
496 	public void testOnlyOption_f1_6_f2_14_e() throws Exception {
497 		final Git git = new Git(db);
498 		prepare_f3_f2_14(git, E);
499 		prepare_f1_6(git);
500 		executeAndCheck_f1_6_f2_14(git, E);
501 	}
502 
503 	@Test
504 	public void testOnlyOption_f1_7_a() throws Exception {
505 		final Git git = new Git(db);
506 		prepare_f3(git, A);
507 		prepare_f1_7(git);
508 		executeAndCheck_f1_7(git, A);
509 	}
510 
511 	@Test
512 	public void testOnlyOption_f1_7_b() throws Exception {
513 		final Git git = new Git(db);
514 		prepare_f3(git, B);
515 		prepare_f1_7(git);
516 		executeAndCheck_f1_7(git, B);
517 	}
518 
519 	@Test
520 	public void testOnlyOption_f1_7_c() throws Exception {
521 		final Git git = new Git(db);
522 		prepare_f3(git, C);
523 		prepare_f1_7(git);
524 		executeAndCheck_f1_7(git, C);
525 	}
526 
527 	@Test
528 	public void testOnlyOption_f1_7_d() throws Exception {
529 		final Git git = new Git(db);
530 		prepare_f3(git, D);
531 		prepare_f1_7(git);
532 		executeAndCheck_f1_7(git, D);
533 	}
534 
535 	@Test
536 	public void testOnlyOption_f1_7_e() throws Exception {
537 		final Git git = new Git(db);
538 		prepare_f3(git, E);
539 		prepare_f1_7(git);
540 		executeAndCheck_f1_7(git, E);
541 	}
542 
543 	@Test
544 	public void testOnlyOption_f1_7_f2_14_a() throws Exception {
545 		final Git git = new Git(db);
546 		prepare_f3_f2_14(git, A);
547 		prepare_f1_7(git);
548 		executeAndCheck_f1_7_f2_14(git, A);
549 	}
550 
551 	@Test
552 	public void testOnlyOption_f1_7_f2_14_b() throws Exception {
553 		final Git git = new Git(db);
554 		prepare_f3_f2_14(git, B);
555 		prepare_f1_7(git);
556 		executeAndCheck_f1_7_f2_14(git, B);
557 	}
558 
559 	@Test
560 	public void testOnlyOption_f1_7_f2_14_c() throws Exception {
561 		final Git git = new Git(db);
562 		prepare_f3_f2_14(git, C);
563 		prepare_f1_7(git);
564 		executeAndCheck_f1_7_f2_14(git, C);
565 	}
566 
567 	@Test
568 	public void testOnlyOption_f1_7_f2_14_d() throws Exception {
569 		final Git git = new Git(db);
570 		prepare_f3_f2_14(git, D);
571 		prepare_f1_7(git);
572 		executeAndCheck_f1_7_f2_14(git, D);
573 	}
574 
575 	@Test
576 	public void testOnlyOption_f1_7_f2_14_e() throws Exception {
577 		final Git git = new Git(db);
578 		prepare_f3_f2_14(git, E);
579 		prepare_f1_7(git);
580 		executeAndCheck_f1_7_f2_14(git, E);
581 	}
582 
583 	@Test
584 	public void testOnlyOption_f1_8_a() throws Exception {
585 		final Git git = new Git(db);
586 		prepare_f3(git, A);
587 		prepare_f1_8(git);
588 		executeAndCheck_f1_8(git, A);
589 	}
590 
591 	@Test
592 	public void testOnlyOption_f1_8_b() throws Exception {
593 		final Git git = new Git(db);
594 		prepare_f3(git, B);
595 		prepare_f1_8(git);
596 		executeAndCheck_f1_8(git, B);
597 	}
598 
599 	@Test
600 	public void testOnlyOption_f1_8_c() throws Exception {
601 		final Git git = new Git(db);
602 		prepare_f3(git, C);
603 		prepare_f1_8(git);
604 		executeAndCheck_f1_8(git, C);
605 	}
606 
607 	@Test
608 	public void testOnlyOption_f1_8_d() throws Exception {
609 		final Git git = new Git(db);
610 		prepare_f3(git, D);
611 		prepare_f1_8(git);
612 		executeAndCheck_f1_8(git, D);
613 	}
614 
615 	@Test
616 	public void testOnlyOption_f1_8_e() throws Exception {
617 		final Git git = new Git(db);
618 		prepare_f3(git, E);
619 		prepare_f1_8(git);
620 		executeAndCheck_f1_8(git, E);
621 	}
622 
623 	@Test
624 	public void testOnlyOption_f1_9_a() throws Exception {
625 		final Git git = new Git(db);
626 		prepare_f3(git, A);
627 		prepare_f1_9(git);
628 		executeAndCheck_f1_9(git, A);
629 	}
630 
631 	@Test
632 	public void testOnlyOption_f1_9_b() throws Exception {
633 		final Git git = new Git(db);
634 		prepare_f3(git, B);
635 		prepare_f1_9(git);
636 		executeAndCheck_f1_9(git, B);
637 	}
638 
639 	@Test
640 	public void testOnlyOption_f1_9_c() throws Exception {
641 		final Git git = new Git(db);
642 		prepare_f3(git, C);
643 		prepare_f1_9(git);
644 		executeAndCheck_f1_9(git, C);
645 	}
646 
647 	@Test
648 	public void testOnlyOption_f1_9_d() throws Exception {
649 		final Git git = new Git(db);
650 		prepare_f3(git, D);
651 		prepare_f1_9(git);
652 		executeAndCheck_f1_9(git, D);
653 	}
654 
655 	@Test
656 	public void testOnlyOption_f1_9_e() throws Exception {
657 		final Git git = new Git(db);
658 		prepare_f3(git, E);
659 		prepare_f1_9(git);
660 		executeAndCheck_f1_9(git, E);
661 	}
662 
663 	@Test
664 	public void testOnlyOption_f1_10_a() throws Exception {
665 		final Git git = new Git(db);
666 		prepare_f3(git, A);
667 		prepare_f1_10(git);
668 		executeAndCheck_f1_10(git, A);
669 	}
670 
671 	@Test
672 	public void testOnlyOption_f1_10_b() throws Exception {
673 		final Git git = new Git(db);
674 		prepare_f3(git, B);
675 		prepare_f1_10(git);
676 		executeAndCheck_f1_10(git, B);
677 	}
678 
679 	@Test
680 	public void testOnlyOption_f1_10_c() throws Exception {
681 		final Git git = new Git(db);
682 		prepare_f3(git, C);
683 		prepare_f1_10(git);
684 		executeAndCheck_f1_10(git, C);
685 	}
686 
687 	@Test
688 	public void testOnlyOption_f1_10_d() throws Exception {
689 		final Git git = new Git(db);
690 		prepare_f3(git, D);
691 		prepare_f1_10(git);
692 		executeAndCheck_f1_10(git, D);
693 	}
694 
695 	@Test
696 	public void testOnlyOption_f1_10_e() throws Exception {
697 		final Git git = new Git(db);
698 		prepare_f3(git, E);
699 		prepare_f1_10(git);
700 		executeAndCheck_f1_10(git, E);
701 	}
702 
703 	@Test
704 	public void testOnlyOption_f1_11_a() throws Exception {
705 		final Git git = new Git(db);
706 		prepare_f3(git, A);
707 		prepare_f1_11(git);
708 		executeAndCheck_f1_11(git, A);
709 	}
710 
711 	@Test
712 	public void testOnlyOption_f1_11_b() throws Exception {
713 		final Git git = new Git(db);
714 		prepare_f3(git, B);
715 		prepare_f1_11(git);
716 		executeAndCheck_f1_11(git, B);
717 	}
718 
719 	@Test
720 	public void testOnlyOption_f1_11_c() throws Exception {
721 		final Git git = new Git(db);
722 		prepare_f3(git, C);
723 		prepare_f1_11(git);
724 		executeAndCheck_f1_11(git, C);
725 	}
726 
727 	@Test
728 	public void testOnlyOption_f1_11_d() throws Exception {
729 		final Git git = new Git(db);
730 		prepare_f3(git, D);
731 		prepare_f1_11(git);
732 		executeAndCheck_f1_11(git, D);
733 	}
734 
735 	@Test
736 	public void testOnlyOption_f1_11_e() throws Exception {
737 		final Git git = new Git(db);
738 		prepare_f3(git, E);
739 		prepare_f1_11(git);
740 		executeAndCheck_f1_11(git, E);
741 	}
742 
743 	@Test
744 	public void testOnlyOption_f1_12_a() throws Exception {
745 		final Git git = new Git(db);
746 		prepare_f3(git, A);
747 		prepare_f1_12(git);
748 		executeAndCheck_f1_12(git, A);
749 	}
750 
751 	@Test
752 	public void testOnlyOption_f1_12_b() throws Exception {
753 		final Git git = new Git(db);
754 		prepare_f3(git, B);
755 		prepare_f1_12(git);
756 		executeAndCheck_f1_12(git, B);
757 	}
758 
759 	@Test
760 	public void testOnlyOption_f1_12_c() throws Exception {
761 		final Git git = new Git(db);
762 		prepare_f3(git, C);
763 		prepare_f1_12(git);
764 		executeAndCheck_f1_12(git, C);
765 	}
766 
767 	@Test
768 	public void testOnlyOption_f1_12_d() throws Exception {
769 		final Git git = new Git(db);
770 		prepare_f3(git, D);
771 		prepare_f1_12(git);
772 		executeAndCheck_f1_12(git, D);
773 	}
774 
775 	@Test
776 	public void testOnlyOption_f1_12_e() throws Exception {
777 		final Git git = new Git(db);
778 		prepare_f3(git, E);
779 		prepare_f1_12(git);
780 		executeAndCheck_f1_12(git, E);
781 	}
782 
783 	@Test
784 	public void testOnlyOption_f1_12_f2_14_a() throws Exception {
785 		final Git git = new Git(db);
786 		prepare_f3_f2_14(git, A);
787 		prepare_f1_12(git);
788 		executeAndCheck_f1_12_f2_14(git, A);
789 	}
790 
791 	@Test
792 	public void testOnlyOption_f1_12_f2_14_b() throws Exception {
793 		final Git git = new Git(db);
794 		prepare_f3_f2_14(git, B);
795 		prepare_f1_12(git);
796 		executeAndCheck_f1_12_f2_14(git, B);
797 	}
798 
799 	@Test
800 	public void testOnlyOption_f1_12_f2_14_c() throws Exception {
801 		final Git git = new Git(db);
802 		prepare_f3_f2_14(git, C);
803 		prepare_f1_12(git);
804 		executeAndCheck_f1_12_f2_14(git, C);
805 	}
806 
807 	@Test
808 	public void testOnlyOption_f1_12_f2_14_d() throws Exception {
809 		final Git git = new Git(db);
810 		prepare_f3_f2_14(git, D);
811 		prepare_f1_12(git);
812 		executeAndCheck_f1_12_f2_14(git, D);
813 	}
814 
815 	@Test
816 	public void testOnlyOption_f1_12_f2_14_e() throws Exception {
817 		final Git git = new Git(db);
818 		prepare_f3_f2_14(git, E);
819 		prepare_f1_12(git);
820 		executeAndCheck_f1_12_f2_14(git, E);
821 	}
822 
823 	@Test
824 	public void testOnlyOption_f1_13_a() throws Exception {
825 		final Git git = new Git(db);
826 		prepare_f3(git, A);
827 		prepare_f1_13(git);
828 		executeAndCheck_f1_13(git, A);
829 	}
830 
831 	@Test
832 	public void testOnlyOption_f1_13_b() throws Exception {
833 		final Git git = new Git(db);
834 		prepare_f3(git, B);
835 		prepare_f1_13(git);
836 		executeAndCheck_f1_13(git, B);
837 	}
838 
839 	@Test
840 	public void testOnlyOption_f1_13_c() throws Exception {
841 		final Git git = new Git(db);
842 		prepare_f3(git, C);
843 		prepare_f1_13(git);
844 		executeAndCheck_f1_13(git, C);
845 	}
846 
847 	@Test
848 	public void testOnlyOption_f1_13_d() throws Exception {
849 		final Git git = new Git(db);
850 		prepare_f3(git, D);
851 		prepare_f1_13(git);
852 		executeAndCheck_f1_13(git, D);
853 	}
854 
855 	@Test
856 	public void testOnlyOption_f1_13_e() throws Exception {
857 		final Git git = new Git(db);
858 		prepare_f3(git, E);
859 		prepare_f1_13(git);
860 		executeAndCheck_f1_13(git, E);
861 	}
862 
863 	@Test
864 	public void testOnlyOption_f1_14_a() throws Exception {
865 		final Git git = new Git(db);
866 		prepare_f3(git, A);
867 		prepare_f1_14(git);
868 		executeAndCheck_f1_14(git, A);
869 	}
870 
871 	@Test
872 	public void testOnlyOption_f1_14_b() throws Exception {
873 		final Git git = new Git(db);
874 		prepare_f3(git, B);
875 		prepare_f1_14(git);
876 		executeAndCheck_f1_14(git, B);
877 	}
878 
879 	@Test
880 	public void testOnlyOption_f1_14_c() throws Exception {
881 		final Git git = new Git(db);
882 		prepare_f3(git, C);
883 		prepare_f1_14(git);
884 		executeAndCheck_f1_14(git, C);
885 	}
886 
887 	@Test
888 	public void testOnlyOption_f1_14_d() throws Exception {
889 		final Git git = new Git(db);
890 		prepare_f3(git, D);
891 		prepare_f1_14(git);
892 		executeAndCheck_f1_14(git, D);
893 	}
894 
895 	@Test
896 	public void testOnlyOption_f1_14_e() throws Exception {
897 		final Git git = new Git(db);
898 		prepare_f3(git, E);
899 		prepare_f1_14(git);
900 		executeAndCheck_f1_14(git, E);
901 	}
902 
903 	@Test
904 	public void testOnlyOptionWithDirectory() throws Exception {
905 		final Git git = new Git(db);
906 
907 		// write files
908 		final File f1 = writeTrashFile("d1/d2/f1.txt", "c1");
909 		writeTrashFile("d1/d2/f2.txt", "c2");
910 		final File f3 = writeTrashFile("d1/f3.txt", "c3");
911 		writeTrashFile("d1/f4.txt", "c4");
912 		final File f5 = writeTrashFile("d3/d4/f5.txt", "c5");
913 		writeTrashFile("d3/d4/f6.txt", "c6");
914 		final File f7 = writeTrashFile("d3/f7.txt", "c7");
915 		writeTrashFile("d3/f8.txt", "c8");
916 		final File f9 = writeTrashFile("d5/f9.txt", "c9");
917 		writeTrashFile("d5/f10.txt", "c10");
918 		final File f11 = writeTrashFile("d6/f11.txt", "c11");
919 		writeTrashFile("d6/f12.txt", "c12");
920 
921 		// add files
922 		git.add().addFilepattern(".").call();
923 
924 		// modify files, but do not stage changes
925 		write(f1, "c1'");
926 		write(f3, "c3'");
927 		write(f5, "c5'");
928 		write(f7, "c7'");
929 		write(f9, "c9'");
930 		write(f11, "c11'");
931 
932 		// commit selected files only
933 		git.commit().setOnly("d1").setOnly("d3/d4/").setOnly("d5")
934 				.setOnly("d6/f11.txt").setMessage(MSG).call();
935 
936 		assertEquals("c1'", getHead(git, "d1/d2/f1.txt"));
937 		assertEquals("c2", getHead(git, "d1/d2/f2.txt"));
938 		assertEquals("c3'", getHead(git, "d1/f3.txt"));
939 		assertEquals("c4", getHead(git, "d1/f4.txt"));
940 		assertEquals("c5'", getHead(git, "d3/d4/f5.txt"));
941 		assertEquals("c6", getHead(git, "d3/d4/f6.txt"));
942 		assertEquals("", getHead(git, "d3/f7.txt"));
943 		assertEquals("", getHead(git, "d3/f8.txt"));
944 		assertEquals("c9'", getHead(git, "d5/f9.txt"));
945 		assertEquals("c10", getHead(git, "d5/f10.txt"));
946 		assertEquals("c11'", getHead(git, "d6/f11.txt"));
947 		assertEquals("", getHead(git, "d6/f12.txt"));
948 		assertEquals("[d1/d2/f1.txt, mode:100644, content:c1']"
949 				+ "[d1/d2/f2.txt, mode:100644, content:c2]"
950 				+ "[d1/f3.txt, mode:100644, content:c3']"
951 				+ "[d1/f4.txt, mode:100644, content:c4]"
952 				+ "[d3/d4/f5.txt, mode:100644, content:c5']"
953 				+ "[d3/d4/f6.txt, mode:100644, content:c6]"
954 				+ "[d3/f7.txt, mode:100644, content:c7]"
955 				+ "[d3/f8.txt, mode:100644, content:c8]"
956 				+ "[d5/f10.txt, mode:100644, content:c10]"
957 				+ "[d5/f9.txt, mode:100644, content:c9']"
958 				+ "[d6/f11.txt, mode:100644, content:c11']"
959 				+ "[d6/f12.txt, mode:100644, content:c12]", indexState(CONTENT));
960 	}
961 
962 	@SuppressWarnings("unused")
963 	private File prepare_f1_1(final Git git) throws IOException {
964 		return writeTrashFile(F1, "c1");
965 	}
966 
967 	private File prepare_f1_2(final Git git) throws Exception {
968 		final File f1 = prepare_f1_4(git);
969 		f1.delete();
970 		return f1;
971 	}
972 
973 	private File prepare_f1_3(final Git git) throws Exception {
974 		final File f1 = prepare_f1_7(git);
975 		git.rm().addFilepattern(F1).call();
976 		return f1;
977 	}
978 
979 	private File prepare_f1_4(final Git git) throws Exception {
980 		final File f1 = prepare_f1_1(git);
981 		git.add().addFilepattern(F1).call();
982 		return f1;
983 	}
984 
985 	private File prepare_f1_5(final Git git) throws Exception {
986 		final File f1 = prepare_f1_7(git);
987 		f1.delete();
988 		return f1;
989 	}
990 
991 	private File prepare_f1_6(final Git git) throws Exception {
992 		final File f1 = prepare_f1_3(git);
993 		write(f1, "c1");
994 		return f1;
995 	}
996 
997 	private File prepare_f1_7(final Git git) throws Exception {
998 		final File f1 = prepare_f1_4(git);
999 		git.commit().setOnly(F1).setMessage(MSG).call();
1000 		return f1;
1001 	}
1002 
1003 	private File prepare_f1_8(final Git git) throws Exception {
1004 		final File f1 = prepare_f1_4(git);
1005 		write(f1, "c1'");
1006 		return f1;
1007 	}
1008 
1009 	private File prepare_f1_9(final Git git) throws Exception {
1010 		final File f1 = prepare_f1_3(git);
1011 		write(f1, "c1'");
1012 		return f1;
1013 	}
1014 
1015 	private File prepare_f1_10(final Git git) throws Exception {
1016 		final File f1 = prepare_f1_9(git);
1017 		git.add().addFilepattern(F1).call();
1018 		f1.delete();
1019 		return f1;
1020 	}
1021 
1022 	private File prepare_f1_11(final Git git) throws Exception {
1023 		final File f1 = prepare_f1_7(git);
1024 		write(f1, "c1'");
1025 		return f1;
1026 	}
1027 
1028 	private File prepare_f1_12(final Git git) throws Exception {
1029 		final File f1 = prepare_f1_13(git);
1030 		write(f1, "c1");
1031 		return f1;
1032 	}
1033 
1034 	private File prepare_f1_13(final Git git) throws Exception {
1035 		final File f1 = prepare_f1_11(git);
1036 		git.add().addFilepattern(F1).call();
1037 		return f1;
1038 	}
1039 
1040 	private File prepare_f1_14(final Git git) throws Exception {
1041 		final File f1 = prepare_f1_13(git);
1042 		write(f1, "c1''");
1043 		return f1;
1044 	}
1045 
1046 	private void executeAndCheck_f1_1(final Git git, final int state)
1047 			throws Exception {
1048 		JGitInternalException exception = null;
1049 		try {
1050 			git.commit().setOnly(F1).setMessage(MSG).call();
1051 		} catch (JGitInternalException e) {
1052 			exception = e;
1053 		}
1054 		assertNotNull(exception);
1055 		assertTrue(exception.getMessage().contains(F1));
1056 
1057 		assertEquals(expected_f3_head(state), getHead(git, F3));
1058 		assertEquals(expected_f3_idx(state), indexState(CONTENT));
1059 	}
1060 
1061 	private void executeAndCheck_f1_1_f2_f14(final Git git, final int state)
1062 			throws Exception {
1063 		JGitInternalException exception = null;
1064 		try {
1065 			git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
1066 		} catch (JGitInternalException e) {
1067 			exception = e;
1068 		}
1069 		assertNotNull(exception);
1070 		assertTrue(exception.getMessage().contains(F1));
1071 
1072 		assertEquals("c2", getHead(git, F2));
1073 		assertEquals(expected_f3_head(state), getHead(git, F3));
1074 		assertEquals("[f2.txt, mode:100644, content:c2']"
1075 				+ expected_f3_idx(state), indexState(CONTENT));
1076 	}
1077 
1078 	private void executeAndCheck_f1_2(final Git git, final int state)
1079 			throws Exception {
1080 		JGitInternalException exception = null;
1081 		try {
1082 			git.commit().setOnly(F1).setMessage(MSG).call();
1083 		} catch (JGitInternalException e) {
1084 			exception = e;
1085 		}
1086 		assertNotNull(exception);
1087 		assertTrue(exception.getMessage().contains("No changes"));
1088 
1089 		assertEquals(expected_f3_head(state), getHead(git, F3));
1090 		assertEquals("[f1.txt, mode:100644, content:c1]"
1091 				+ expected_f3_idx(state), indexState(CONTENT));
1092 	}
1093 
1094 	private void executeAndCheck_f1_2_f2_f14(final Git git, final int state)
1095 			throws Exception {
1096 		git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
1097 
1098 		assertEquals("", getHead(git, F1));
1099 		assertEquals("c2''", getHead(git, F2));
1100 		assertEquals(expected_f3_head(state), getHead(git, F3));
1101 		assertEquals("[f2.txt, mode:100644, content:c2'']"
1102 				+ expected_f3_idx(state), indexState(CONTENT));
1103 	}
1104 
1105 	private void executeAndCheck_f1_3(final Git git, final int state)
1106 			throws Exception {
1107 		git.commit().setOnly(F1).setMessage(MSG).call();
1108 
1109 		assertEquals("", getHead(git, F1));
1110 		assertEquals(expected_f3_head(state), getHead(git, F3));
1111 		assertEquals(expected_f3_idx(state), indexState(CONTENT));
1112 	}
1113 
1114 	private void executeAndCheck_f1_4(final Git git, final int state)
1115 			throws Exception {
1116 		git.commit().setOnly(F1).setMessage(MSG).call();
1117 
1118 		assertEquals("c1", getHead(git, F1));
1119 		assertEquals(expected_f3_head(state), getHead(git, F3));
1120 		assertEquals("[f1.txt, mode:100644, content:c1]"
1121 				+ expected_f3_idx(state), indexState(CONTENT));
1122 	}
1123 
1124 	private void executeAndCheck_f1_5(final Git git, final int state)
1125 			throws Exception {
1126 		executeAndCheck_f1_3(git, state);
1127 	}
1128 
1129 	private void executeAndCheck_f1_6(final Git git, final int state)
1130 			throws Exception {
1131 		JGitInternalException exception = null;
1132 		try {
1133 			git.commit().setOnly(F1).setMessage(MSG).call();
1134 		} catch (JGitInternalException e) {
1135 			exception = e;
1136 		}
1137 		assertNotNull(exception);
1138 		assertTrue(exception.getMessage().contains("No changes"));
1139 
1140 		assertEquals(expected_f3_head(state), getHead(git, F3));
1141 		assertEquals(expected_f3_idx(state), indexState(CONTENT));
1142 	}
1143 
1144 	private void executeAndCheck_f1_6_f2_14(final Git git, final int state)
1145 			throws Exception {
1146 		git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
1147 
1148 		assertEquals("c1", getHead(git, F1));
1149 		assertEquals("c2''", getHead(git, F2));
1150 		assertEquals(expected_f3_head(state), getHead(git, F3));
1151 		assertEquals("[f1.txt, mode:100644, content:c1]"
1152 				+ "[f2.txt, mode:100644, content:c2'']"
1153 				+ expected_f3_idx(state), indexState(CONTENT));
1154 	}
1155 
1156 	private void executeAndCheck_f1_7(final Git git, final int state)
1157 			throws Exception {
1158 		executeAndCheck_f1_2(git, state);
1159 	}
1160 
1161 	private void executeAndCheck_f1_7_f2_14(final Git git, final int state)
1162 			throws Exception {
1163 		executeAndCheck_f1_6_f2_14(git, state);
1164 	}
1165 
1166 	private void executeAndCheck_f1_8(final Git git, final int state)
1167 			throws Exception {
1168 		git.commit().setOnly(F1).setMessage(MSG).call();
1169 
1170 		assertEquals("c1'", getHead(git, F1));
1171 		assertEquals(expected_f3_head(state), getHead(git, F3));
1172 		assertEquals("[f1.txt, mode:100644, content:c1']"
1173 				+ expected_f3_idx(state), indexState(CONTENT));
1174 	}
1175 
1176 	private void executeAndCheck_f1_9(final Git git, final int state)
1177 			throws Exception {
1178 		executeAndCheck_f1_8(git, state);
1179 	}
1180 
1181 	private void executeAndCheck_f1_10(final Git git, final int state)
1182 			throws Exception {
1183 		executeAndCheck_f1_3(git, state);
1184 	}
1185 
1186 	private void executeAndCheck_f1_11(final Git git, final int state)
1187 			throws Exception {
1188 		executeAndCheck_f1_8(git, state);
1189 	}
1190 
1191 	private void executeAndCheck_f1_12(final Git git, final int state)
1192 			throws Exception {
1193 		JGitInternalException exception = null;
1194 		try {
1195 			git.commit().setOnly(F1).setMessage(MSG).call();
1196 		} catch (JGitInternalException e) {
1197 			exception = e;
1198 		}
1199 		assertNotNull(exception);
1200 		assertTrue(exception.getMessage().contains("No changes"));
1201 
1202 		assertEquals(expected_f3_head(state), getHead(git, F3));
1203 		assertEquals("[f1.txt, mode:100644, content:c1']"
1204 				+ expected_f3_idx(state), indexState(CONTENT));
1205 	}
1206 
1207 	private void executeAndCheck_f1_12_f2_14(final Git git, final int state)
1208 			throws Exception {
1209 		executeAndCheck_f1_6_f2_14(git, state);
1210 	}
1211 
1212 	private void executeAndCheck_f1_13(final Git git, final int state)
1213 			throws Exception {
1214 		executeAndCheck_f1_8(git, state);
1215 	}
1216 
1217 	private void executeAndCheck_f1_14(final Git git, final int state)
1218 			throws Exception {
1219 		git.commit().setOnly(F1).setMessage(MSG).call();
1220 
1221 		assertEquals("c1''", getHead(git, F1));
1222 		assertEquals(expected_f3_head(state), getHead(git, F3));
1223 		assertEquals("[f1.txt, mode:100644, content:c1'']"
1224 				+ expected_f3_idx(state), indexState(CONTENT));
1225 	}
1226 
1227 	private void prepare_f3(final Git git, final int state) throws Exception {
1228 		prepare_f3_f2_14(git, state, false);
1229 	}
1230 
1231 	private void prepare_f3_f2_14(final Git git, final int state)
1232 			throws Exception {
1233 		prepare_f3_f2_14(git, state, true);
1234 	}
1235 
1236 	private void prepare_f3_f2_14(final Git git, final int state,
1237 			final boolean include_f2) throws Exception {
1238 		File f2 = null;
1239 		if (include_f2) {
1240 			f2 = writeTrashFile(F2, "c2");
1241 			git.add().addFilepattern(F2).call();
1242 			git.commit().setMessage(MSG).call();
1243 		}
1244 
1245 		if (state >= 1) {
1246 			writeTrashFile(F3, "c3");
1247 			git.add().addFilepattern(F3).call();
1248 		}
1249 		if (state >= 2)
1250 			git.commit().setMessage(MSG).call();
1251 		if (state >= 3)
1252 			git.rm().addFilepattern(F3).call();
1253 		if (state == 4) {
1254 			writeTrashFile(F3, "c3'");
1255 			git.add().addFilepattern(F3).call();
1256 		}
1257 
1258 		if (include_f2) {
1259 			write(f2, "c2'");
1260 			git.add().addFilepattern(F2).call();
1261 			write(f2, "c2''");
1262 		}
1263 	}
1264 
1265 	private static String expected_f3_head(final int state) {
1266 		switch (state) {
1267 		case 0:
1268 		case 1:
1269 			return "";
1270 		case 2:
1271 		case 3:
1272 		case 4:
1273 			return "c3";
1274 		}
1275 		return null;
1276 	}
1277 
1278 	private static String expected_f3_idx(final int state) {
1279 		switch (state) {
1280 		case 0:
1281 		case 3:
1282 			return "";
1283 		case 1:
1284 		case 2:
1285 			return "[f3.txt, mode:100644, content:c3]";
1286 		case 4:
1287 			return "[f3.txt, mode:100644, content:c3']";
1288 		}
1289 		return null;
1290 	}
1291 
1292 	static private String getHead(Git git, String path)
1293 			throws Exception {
1294 		try {
1295 			final Repository repo = git.getRepository();
1296 			final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
1297 			if (headId == null) {
1298 				return "";
1299 			}
1300 			try (RevWalk rw = new RevWalk(repo)) {
1301 				final TreeWalk tw = TreeWalk.forPath(repo, path,
1302 						rw.parseTree(headId));
1303 				if (tw == null) {
1304 					return "";
1305 				}
1306 				return new String(tw.getObjectReader().open(tw.getObjectId(0))
1307 						.getBytes());
1308 			}
1309 		} catch (Exception e) {
1310 			return "";
1311 		}
1312 	}
1313 }