From 59baf9148e4b16028203d9e881136ab4c005202c Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 6 Apr 2013 14:03:24 +0200 Subject: [PATCH] Detect and handle a checkout conflict during merge nicely Report the conflicting files nicely and inform the user. Change-Id: I75d464d4156d10c6cc6c7ce5a321e2c9fb0df375 --- .../org/eclipse/jgit/pgm/CLIText.properties | 2 ++ .../src/org/eclipse/jgit/pgm/CLIText.java | 2 ++ .../src/org/eclipse/jgit/pgm/Merge.java | 14 +++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) 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 eed05e89f5..07d9c00c7e 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 @@ jgitVersion=jgit version {0} 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 64bd18e867..1f14fa272b 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 class CLIText extends TranslationBundle { /***/ 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 97198259d3..e25ac4f3ef 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.Git; 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 @@ class Merge extends TextBuiltin { 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 @@ class Merge extends TextBuiltin { .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, -- 2.39.5