diff options
author | Markus Duft <markus.duft@salomon.at> | 2012-07-13 08:25:25 +0200 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2013-01-11 20:32:44 -0500 |
commit | baf7ca9cc0d2bdf237a9bb19486d6fde5250a7f5 (patch) | |
tree | 0a9d7f0fa4037f6b8f25f97fbf106c3663b80f56 /org.eclipse.jgit | |
parent | 912ef3da19c7bc1975805e1e3e9746baf479c2be (diff) | |
download | jgit-baf7ca9cc0d2bdf237a9bb19486d6fde5250a7f5.tar.gz jgit-baf7ca9cc0d2bdf237a9bb19486d6fde5250a7f5.zip |
Improve handling of checkout conflicts
This converts a checkout conflict exception into a RebaseResult /
MergeResult containing the conflicting paths, which enables EGit (or
others) to handle the situation in a user-friendly way
Change-Id: I48d9bdcc1e98095576513a54a225a42409f301f3
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 80 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java index 1c930ebeb3..82272168aa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeResult.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.api; import java.text.MessageFormat; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.jgit.internal.JGitText; @@ -177,6 +178,21 @@ public class MergeResult { public boolean isSuccessful() { return false; } + }, + /** + * Status representing a checkout conflict, meaning that nothing could + * be merged, as the pre-scan for the trees already failed for certain + * files (i.e. local modifications prevent checkout of files). + */ + CHECKOUT_CONFLICT { + public String toString() { + return "Checkout Conflict"; + } + + @Override + public boolean isSuccessful() { + return false; + } }; /** @@ -201,6 +217,8 @@ public class MergeResult { private Map<String, MergeFailureReason> failingPaths; + private List<String> checkoutConflicts; + /** * @param newHead * the object the head points at after the merge @@ -295,6 +313,18 @@ public class MergeResult { } /** + * Creates a new result that represents a checkout conflict before the + * operation even started for real. + * + * @param checkoutConflicts + * the conflicting files + */ + public MergeResult(List<String> checkoutConflicts) { + this.checkoutConflicts = checkoutConflicts; + this.mergeStatus = MergeStatus.CHECKOUT_CONFLICT; + } + + /** * @return the object the head points at after the merge */ public ObjectId getNewHead() { @@ -450,4 +480,14 @@ public class MergeResult { public Map<String, MergeFailureReason> getFailingPaths() { return failingPaths; } + + /** + * Returns a list of paths that cause a checkout conflict. These paths + * prevent the operation from even starting. + * + * @return the list of files that caused the checkout conflict. + */ + public List<String> getCheckoutConflicts() { + return checkoutConflicts; + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 3f7feb936f..5158c8533b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -355,6 +355,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> { return RebaseResult.OK_RESULT; } return RebaseResult.FAST_FORWARD_RESULT; + } catch (CheckoutConflictException cce) { + return new RebaseResult(cce.getConflictingPaths()); } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } @@ -880,13 +882,18 @@ public class RebaseCommand extends GitCommand<RebaseResult> { return RawParseUtils.decode(content, 0, end); } - private boolean checkoutCommit(RevCommit commit) throws IOException { + private boolean checkoutCommit(RevCommit commit) throws IOException, + CheckoutConflictException { try { RevCommit head = walk.parseCommit(repo.resolve(Constants.HEAD)); DirCacheCheckout dco = new DirCacheCheckout(repo, head.getTree(), repo.lockDirCache(), commit.getTree()); dco.setFailOnConflict(true); - dco.checkout(); + try { + dco.checkout(); + } catch (org.eclipse.jgit.errors.CheckoutConflictException cce) { + throw new CheckoutConflictException(dco.getConflicts(), cce); + } // update the HEAD RefUpdate refUpdate = repo.updateRef(Constants.HEAD, true); refUpdate.setExpectedOldObjectId(head); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java index a09f8c28af..59655570c0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.api; +import java.util.List; import java.util.Map; import org.eclipse.jgit.merge.ResolveMerger; @@ -93,6 +94,15 @@ public class RebaseResult { } }, /** + * Conflicts: checkout of target HEAD failed + */ + CONFLICTS { + @Override + public boolean isSuccessful() { + return false; + } + }, + /** * Already up-to-date */ UP_TO_DATE { @@ -148,6 +158,8 @@ public class RebaseResult { private Map<String, MergeFailureReason> failingPaths; + private List<String> conflicts; + private RebaseResult(Status status) { this.status = status; currentCommit = null; @@ -177,6 +189,18 @@ public class RebaseResult { } /** + * Create <code>RebaseResult</code> with status {@link Status#CONFLICTS} + * + * @param conflicts + * the list of conflicting paths + */ + RebaseResult(List<String> conflicts) { + status = Status.CONFLICTS; + currentCommit = null; + this.conflicts = conflicts; + } + + /** * @return the overall status */ public Status getStatus() { @@ -199,4 +223,11 @@ public class RebaseResult { public Map<String, MergeFailureReason> getFailingPaths() { return failingPaths; } + + /** + * @return the list of conflicts if status is {@link Status#CONFLICTS} + */ + public List<String> getConflicts() { + return conflicts; + } } |