diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2011-12-08 23:33:53 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2011-12-08 23:33:53 +0100 |
commit | 26b573862912b2faf3824bb18dfeb44a3b700014 (patch) | |
tree | 6ed5e12926fd8157fb63b771e19813deabc0e27e | |
parent | dfcb43eff1bbdc58b6d286b4d18256ce8af56a78 (diff) | |
download | jgit-26b573862912b2faf3824bb18dfeb44a3b700014.tar.gz jgit-26b573862912b2faf3824bb18dfeb44a3b700014.zip |
Throw API exception when MergeCommand hits checkout conflicts
When MergeCommand hit checkout conflicts it did throw an internal JGit
exception org.eclipse.jgit.errors.CheckoutConflictException instead of
org.eclipse.jgit.api.errors.CheckoutConflictException which it
declares to throw. Hence translate the internal exception to the
exception declared in the API.
Bug: 327573
Change-Id: I1efcd93a43ecbf4a40583e0fc9d8d53cffc98cae
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java | 12 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/errors/CheckoutConflictException.java | 15 |
2 files changed, 24 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index c7a30ebe17..85686da4de 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.api; import java.io.IOException; import java.text.MessageFormat; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -122,6 +123,7 @@ public class MergeCommand extends GitCommand<MergeResult> { Integer.valueOf(commits.size()))); RevWalk revWalk = null; + DirCacheCheckout dco = null; try { Ref head = repo.getRef(Constants.HEAD); if (head == null) @@ -147,7 +149,7 @@ public class MergeCommand extends GitCommand<MergeResult> { ObjectId headId = head.getObjectId(); if (headId == null) { revWalk.parseHeaders(srcCommit); - DirCacheCheckout dco = new DirCacheCheckout(repo, + dco = new DirCacheCheckout(repo, repo.lockDirCache(), srcCommit.getTree()); dco.setFailOnConflict(true); dco.checkout(); @@ -176,7 +178,7 @@ public class MergeCommand extends GitCommand<MergeResult> { // FAST_FORWARD detected: skip doing a real merge but only // update HEAD refLogMessage.append(": " + MergeStatus.FAST_FORWARD); - DirCacheCheckout dco = new DirCacheCheckout(repo, + dco = new DirCacheCheckout(repo, headCommit.getTree(), repo.lockDirCache(), srcCommit.getTree()); dco.setFailOnConflict(true); @@ -214,7 +216,7 @@ public class MergeCommand extends GitCommand<MergeResult> { refLogMessage.append(mergeStrategy.getName()); refLogMessage.append('.'); if (noProblems) { - DirCacheCheckout dco = new DirCacheCheckout(repo, + dco = new DirCacheCheckout(repo, headCommit.getTree(), repo.lockDirCache(), merger.getResultTreeId()); dco.setFailOnConflict(true); @@ -250,6 +252,10 @@ public class MergeCommand extends GitCommand<MergeResult> { } } } + } catch (org.eclipse.jgit.errors.CheckoutConflictException e) { + List<String> conflicts = (dco == null) ? Collections + .<String> emptyList() : dco.getConflicts(); + throw new CheckoutConflictException(conflicts, e); } catch (IOException e) { throw new JGitInternalException( MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/CheckoutConflictException.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/CheckoutConflictException.java index de45c1d8e2..4d5bd1e03c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/CheckoutConflictException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/CheckoutConflictException.java @@ -48,6 +48,20 @@ public class CheckoutConflictException extends GitAPIException { private static final long serialVersionUID = 1L; private List<String> conflictingPaths; + /** + * Translate internal exception to API exception + * + * @param conflictingPaths + * list of conflicting paths + * + * @param e + */ + public CheckoutConflictException(List<String> conflictingPaths, + org.eclipse.jgit.errors.CheckoutConflictException e) { + super(e.getMessage(), e); + this.conflictingPaths = conflictingPaths; + } + CheckoutConflictException(String message, Throwable cause) { super(message, cause); } @@ -73,6 +87,7 @@ public class CheckoutConflictException extends GitAPIException { /** * Adds a new conflicting path + * * @param conflictingPath * @return {@code this} */ |