Browse Source

Detect and handle a checkout conflict during merge nicely

Report the conflicting files nicely and inform the user.

Change-Id: I75d464d4156d10c6cc6c7ce5a321e2c9fb0df375
stable-3.0
Robin Rosenberg 12 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
59baf9148e
  1. 2
      org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
  2. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
  3. 14
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java

2
org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties

@ -65,7 +65,9 @@ jgitVersion=jgit version {0}
lineFormat=# {0} lineFormat=# {0}
listeningOn=Listening on {0} listeningOn=Listening on {0}
mergeConflict=CONFLICT(content): Merge conflict in {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 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. mergeMadeBy=Merge made by the ''{0}'' strategy.
mergedSquashed=Squash commit -- not updating HEAD\nAutomatic merge went well; stopped before committing as requested 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 mergeWentWellStoppedBeforeCommitting=Automatic merge went well; stopped before committing as requested

2
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 jgitVersion;
/***/ public String lineFormat; /***/ public String lineFormat;
/***/ public String listeningOn; /***/ public String listeningOn;
/***/ public String mergeCheckoutConflict;
/***/ public String mergeConflict; /***/ public String mergeConflict;
/***/ public String mergeFailed; /***/ public String mergeFailed;
/***/ public String mergeCheckoutFailed;
/***/ public String mergeMadeBy; /***/ public String mergeMadeBy;
/***/ public String mergedSquashed; /***/ public String mergedSquashed;
/***/ public String mergeWentWellStoppedBeforeCommitting; /***/ public String mergeWentWellStoppedBeforeCommitting;

14
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.MergeCommand;
import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode; 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.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@ -119,7 +120,12 @@ class Merge extends TextBuiltin {
mergeCmd.include(srcRef); mergeCmd.include(srcRef);
else else
mergeCmd.include(src); 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()) { switch (result.getMergeStatus()) {
case ALREADY_UP_TO_DATE: case ALREADY_UP_TO_DATE:
@ -134,6 +140,12 @@ class Merge extends TextBuiltin {
.name())); .name()));
outw.println(result.getMergeStatus().toString()); outw.println(result.getMergeStatus().toString());
break; 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: case CONFLICTING:
for (String collidingPath : result.getConflicts().keySet()) for (String collidingPath : result.getConflicts().keySet())
outw.println(MessageFormat.format(CLIText.get().mergeConflict, outw.println(MessageFormat.format(CLIText.get().mergeConflict,

Loading…
Cancel
Save