From 32a5993227b5f43cb32becdf14d3efb6e88fa847 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 27 Jun 2014 20:22:03 -0700 Subject: [PATCH] Expose conflicting files in CheckoutConflictException Change-Id: I5b3b7b0633354d5ccf0c6c320c0df9c93fdf8eeb Signed-off-by: Ned Twigg Signed-off-by: Matthias Sohn --- .../org/eclipse/jgit/lib/DirCacheCheckoutTest.java | 2 ++ .../jgit/errors/CheckoutConflictException.java | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java index 5578c03d4a..fbe7dd0417 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java @@ -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]); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/CheckoutConflictException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/CheckoutConflictException.java index db29f3f15b..b6010b6983 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/CheckoutConflictException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/CheckoutConflictException.java @@ -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) { -- 2.39.5