2 * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3 * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org>
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * - Neither the name of the Git Development Community nor the
20 * names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 package org
.spearce
.jgit
.lib
;
42 import java
.io
.IOException
;
43 import java
.util
.ArrayList
;
45 import org
.spearce
.jgit
.errors
.CheckoutConflictException
;
47 public class WorkDirCheckoutTest
extends RepositoryTestCase
{
48 public void testFindingConflicts() throws IOException
{
49 GitIndex index
= new GitIndex(db
);
50 index
.add(trash
, writeTrashFile("bar", "bar"));
51 index
.add(trash
, writeTrashFile("foo/bar/baz/qux", "foo/bar"));
52 recursiveDelete(new File(trash
, "bar"));
53 recursiveDelete(new File(trash
, "foo"));
54 writeTrashFile("bar/baz/qux/foo", "another nasty one");
55 writeTrashFile("foo", "troublesome little bugger");
57 WorkDirCheckout workDirCheckout
= new WorkDirCheckout(db
, trash
, index
,
59 workDirCheckout
.prescanOneTree();
60 ArrayList
<String
> conflictingEntries
= workDirCheckout
62 ArrayList
<String
> removedEntries
= workDirCheckout
.getRemoved();
63 assertEquals("bar/baz/qux/foo", conflictingEntries
.get(0));
64 assertEquals("foo", conflictingEntries
.get(1));
66 GitIndex index2
= new GitIndex(db
);
67 recursiveDelete(new File(trash
, "bar"));
68 recursiveDelete(new File(trash
, "foo"));
70 index2
.add(trash
, writeTrashFile("bar/baz/qux/foo", "bar"));
71 index2
.add(trash
, writeTrashFile("foo", "lalala"));
73 workDirCheckout
= new WorkDirCheckout(db
, trash
, index2
, index
);
74 workDirCheckout
.prescanOneTree();
76 conflictingEntries
= workDirCheckout
.getConflicts();
77 removedEntries
= workDirCheckout
.getRemoved();
78 assertTrue(conflictingEntries
.isEmpty());
79 assertTrue(removedEntries
.contains("bar/baz/qux/foo"));
80 assertTrue(removedEntries
.contains("foo"));
83 public void testCheckingOutWithConflicts() throws IOException
{
84 GitIndex index
= new GitIndex(db
);
85 index
.add(trash
, writeTrashFile("bar", "bar"));
86 index
.add(trash
, writeTrashFile("foo/bar/baz/qux", "foo/bar"));
87 recursiveDelete(new File(trash
, "bar"));
88 recursiveDelete(new File(trash
, "foo"));
89 writeTrashFile("bar/baz/qux/foo", "another nasty one");
90 writeTrashFile("foo", "troublesome little bugger");
93 WorkDirCheckout workDirCheckout
= new WorkDirCheckout(db
, trash
,
95 workDirCheckout
.checkout();
96 fail("Should have thrown exception");
97 } catch (CheckoutConflictException e
) {
101 WorkDirCheckout workDirCheckout
= new WorkDirCheckout(db
, trash
, index
,
103 workDirCheckout
.setFailOnConflict(false);
104 workDirCheckout
.checkout();
106 assertTrue(new File(trash
, "bar").isFile());
107 assertTrue(new File(trash
, "foo/bar/baz/qux").isFile());
109 GitIndex index2
= new GitIndex(db
);
110 recursiveDelete(new File(trash
, "bar"));
111 recursiveDelete(new File(trash
, "foo"));
112 index2
.add(trash
, writeTrashFile("bar/baz/qux/foo", "bar"));
113 writeTrashFile("bar/baz/qux/bar", "evil? I thought it said WEEVIL!");
114 index2
.add(trash
, writeTrashFile("foo", "lalala"));
116 workDirCheckout
= new WorkDirCheckout(db
, trash
, index2
, index
);
117 workDirCheckout
.setFailOnConflict(false);
118 workDirCheckout
.checkout();
120 assertTrue(new File(trash
, "bar").isFile());
121 assertTrue(new File(trash
, "foo/bar/baz/qux").isFile());
122 assertNotNull(index2
.getEntry("bar"));
123 assertNotNull(index2
.getEntry("foo/bar/baz/qux"));
124 assertNull(index2
.getEntry("bar/baz/qux/foo"));
125 assertNull(index2
.getEntry("foo"));