Expose conflicting files in CheckoutConflictException

Change-Id: I5b3b7b0633354d5ccf0c6c320c0df9c93fdf8eeb
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Ned Twigg 2014-06-27 20:22:03 -07:00 committed by Matthias Sohn
parent eeeca8042f
commit 32a5993227
2 changed files with 15 additions and 0 deletions

View File

@ -798,6 +798,7 @@ public void testUntrackedConflicts() throws IOException {
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 void testCheckoutHierarchy() throws IOException {
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]);
}
}

View File

@ -56,6 +56,8 @@
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 CheckoutConflictException(String file) {
*/
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) {