Detect and handle a checkout conflict during merge nicely
Report the conflicting files nicely and inform the user.
Change-Id: I75d464d4156d10c6cc6c7ce5a321e2c9fb0df375
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
index eed05e8..07d9c00 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
@@ -65,7 +65,9 @@
lineFormat=# {0}
listeningOn=Listening on {0}
mergeConflict=CONFLICT(content): Merge conflict in {0}
+mergeCheckoutConflict=error: Your local changes to the following files would be overwritten by merge:
mergeFailed=Automatic merge failed; fix conflicts and then commit the result
+mergeCheckoutFailed=Please, commit your changes or stash them before you can merge.
mergeMadeBy=Merge made by the ''{0}'' strategy.
mergedSquashed=Squash commit -- not updating HEAD\nAutomatic merge went well; stopped before committing as requested
mergeWentWellStoppedBeforeCommitting=Automatic merge went well; stopped before committing as requested
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
index 64bd18e..1f14fa2 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
@@ -133,8 +133,10 @@ public static String formatLine(String line) {
/***/ public String jgitVersion;
/***/ public String lineFormat;
/***/ public String listeningOn;
+ /***/ public String mergeCheckoutConflict;
/***/ public String mergeConflict;
/***/ public String mergeFailed;
+ /***/ public String mergeCheckoutFailed;
/***/ public String mergeMadeBy;
/***/ public String mergedSquashed;
/***/ public String mergeWentWellStoppedBeforeCommitting;
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
index 9719825..e25ac4f 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
@@ -51,6 +51,7 @@
import org.eclipse.jgit.api.MergeCommand;
import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
+import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -119,7 +120,12 @@ protected void run() throws Exception {
mergeCmd.include(srcRef);
else
mergeCmd.include(src);
- MergeResult result = mergeCmd.call();
+ MergeResult result;
+ try {
+ result = mergeCmd.call();
+ } catch (CheckoutConflictException e) {
+ result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT
+ }
switch (result.getMergeStatus()) {
case ALREADY_UP_TO_DATE:
@@ -134,6 +140,12 @@ protected void run() throws Exception {
.name()));
outw.println(result.getMergeStatus().toString());
break;
+ case CHECKOUT_CONFLICT:
+ outw.println(CLIText.get().mergeCheckoutConflict);
+ for (String collidingPath : result.getCheckoutConflicts())
+ outw.println("\t" + collidingPath); //$NON-NLS-1$
+ outw.println(CLIText.get().mergeCheckoutFailed);
+ break;
case CONFLICTING:
for (String collidingPath : result.getConflicts().keySet())
outw.println(MessageFormat.format(CLIText.get().mergeConflict,