]> source.dussan.org Git - jgit.git/commitdiff
Expose conflicting files in CheckoutConflictException 04/68104/3
authorNed Twigg <ned.twigg@diffplug.com>
Sat, 28 Jun 2014 03:22:03 +0000 (20:22 -0700)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 11 Apr 2016 20:55:16 +0000 (22:55 +0200)
Change-Id: I5b3b7b0633354d5ccf0c6c320c0df9c93fdf8eeb
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
org.eclipse.jgit/src/org/eclipse/jgit/errors/CheckoutConflictException.java

index 5578c03d4a656286b8b8157217ee6bcd33d7c91a..fbe7dd04178945c2750c63ddc05eb099e738bf89 100644 (file)
@@ -798,6 +798,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
                        fail("didn't get the expected exception");
                } catch (CheckoutConflictException e) {
                        assertConflict("foo");
+                       assertEquals("foo", e.getConflictingFiles()[0]);
                        assertWorkDir(mkmap("foo", "bar", "other", "other"));
                        assertIndex(mk("other"));
                }
@@ -885,6 +886,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
                        assertWorkDir(mkmap("a", "a", "b/c", "b/c", "d", "d", "e/f",
                                        "e/f", "e/g", "e/g3"));
                        assertConflict("e/g");
+                       assertEquals("e/g", e.getConflictingFiles()[0]);
                }
        }
 
index db29f3f15b2a167de9f0f785ad02dd024dd82d9d..b6010b6983565202d641ed44f917a84214f23333 100644 (file)
@@ -56,6 +56,8 @@ import org.eclipse.jgit.internal.JGitText;
 public class CheckoutConflictException extends IOException {
        private static final long serialVersionUID = 1L;
 
+       private final String[] conflicting;
+
        /**
         * Construct a CheckoutConflictException for the specified file
         *
@@ -63,6 +65,7 @@ public class CheckoutConflictException extends IOException {
         */
        public CheckoutConflictException(String file) {
                super(MessageFormat.format(JGitText.get().checkoutConflictWithFile, file));
+               conflicting = new String[] { file };
        }
 
        /**
@@ -72,6 +75,16 @@ public class CheckoutConflictException extends IOException {
         */
        public CheckoutConflictException(String[] files) {
                super(MessageFormat.format(JGitText.get().checkoutConflictWithFiles, buildList(files)));
+               conflicting = files;
+       }
+
+       /**
+        * @return the relative paths of the conflicting files (relative to the
+        *         working directory root).
+        * @since 4.4
+        */
+       public String[] getConflictingFiles() {
+               return conflicting;
        }
 
        private static String buildList(String[] files) {