summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRobin Stocker2011-04-03 13:38:05 (EDT)
committer Robin Stocker2011-04-06 17:06:01 (EDT)
commitd9dcc70255dacea97d1681c4b785c63b5b17ddde (patch)
tree045b04be52a67061613d9bc4be47ab843cfb4743
parentdfb50da14addc638080c8b72d8fe91d82d5f287d (diff)
downloadegit-d9dcc70255dacea97d1681c4b785c63b5b17ddde.zip
egit-d9dcc70255dacea97d1681c4b785c63b5b17ddde.tar.gz
egit-d9dcc70255dacea97d1681c4b785c63b5b17ddde.tar.bz2
Enable cherry-pick conflict resolutionrefs/changes/97/2997/2
When a cherry-pick fails due to conflicts, the user has to resolve the situation. With this change, the repository is set to the "Conflicts" state and the merge tool is enabled. Also, the original commit message and author is preset in the commit dialog. The message includes a "Conflicts" section as in C git. This depends on JGit change I947967fdc2f1d55016c95106b104c2afcc9797a1. Bug: 339092 Change-Id: I5c5b98c98cf8deefa27de6cb94afa189a2cba218 Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties1
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeToolActionHandler.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitUI.java25
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CherryPickHandler.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties2
9 files changed, 65 insertions, 4 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
index 8a6a43f..d520e96 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
@@ -159,6 +159,9 @@ public class CoreText extends NLS {
public static String ResetOperation_resetMergeFailed;
/** */
+ public static String ResetOperation_resetCherryPickFailed;
+
+ /** */
public static String ResetOperation_updatingFailed;
/** */
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
index fab3806..5a541be 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
@@ -57,6 +57,7 @@ ResetOperation_mappingTreeForCommit=mapping tree for commit
ResetOperation_performingReset=Performing {0} reset to {1}
ResetOperation_readingIndex=Reading index
ResetOperation_resetMergeFailed=Resetting merge mode failed
+ResetOperation_resetCherryPickFailed=Resetting cherry pick mode failed
ResetOperation_updatingFailed=Updating {0} failed
MergeOperation_InternalError=An internal error occurred
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java
index 5fe4832..43141a3 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ResetOperation.java
@@ -124,6 +124,8 @@ public class ResetOperation implements IEGitOperation {
|| repository.getRepositoryState().equals(
RepositoryState.MERGING_RESOLVED))
merging = true;
+ final boolean cherryPicking = repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING)
+ || repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING_RESOLVED);
mapObjects();
monitor.worked(1);
@@ -137,6 +139,8 @@ public class ResetOperation implements IEGitOperation {
monitor.worked(1);
if (merging)
resetMerge();
+ if (cherryPicking)
+ resetCherryPick();
monitor.worked(1);
// only refresh if working tree changes
ProjectUtil.refreshValidProjects(validProjects, new SubProgressMonitor(
@@ -150,6 +154,8 @@ public class ResetOperation implements IEGitOperation {
monitor.worked(2);
if (merging)
resetMerge();
+ if (cherryPicking)
+ resetCherryPick();
monitor.worked(1);
break;
@@ -169,6 +175,15 @@ public class ResetOperation implements IEGitOperation {
}
}
+ private void resetCherryPick() throws CoreException {
+ try {
+ repository.writeCherryPickHead(null);
+ repository.writeMergeCommitMsg(null);
+ } catch (IOException e) {
+ throw new TeamException(CoreText.ResetOperation_resetCherryPickFailed, e);
+ }
+ }
+
private void mapObjects() throws TeamException {
final ObjectId commitId;
try {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index ca439a5..09ce138 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -655,6 +655,12 @@ public class UIText extends NLS {
public static String CherryPickHandler_NoCherryPickPerformedTitle;
/** */
+ public static String CherryPickHandler_CherryPickConflictsMessage;
+
+ /** */
+ public static String CherryPickHandler_CherryPickConflictsTitle;
+
+ /** */
public static String CherryPickOperation_Failed;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeToolActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeToolActionHandler.java
index a5f8ee8..f29be99 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeToolActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeToolActionHandler.java
@@ -53,6 +53,8 @@ public class MergeToolActionHandler extends RepositoryActionHandler {
switch (repos[0].getRepositoryState()) {
case MERGING:
// fall through
+ case CHERRY_PICKING:
+ // fall through
case REBASING:
// fall through
case REBASING_INTERACTIVE:
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitUI.java
index 20d3081..72b780d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitUI.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitUI.java
@@ -153,6 +153,7 @@ public class CommitUI {
Repository mergeRepository = null;
amendAllowed = repos.length == 1;
boolean isMergedResolved = false;
+ boolean isCherryPickResolved = false;
for (Repository repo : repos) {
repository = repo;
RepositoryState state = repo.getRepositoryState();
@@ -167,6 +168,10 @@ public class CommitUI {
isMergedResolved = true;
mergeRepository = repo;
}
+ else if (state.equals(RepositoryState.CHERRY_PICKING_RESOLVED)) {
+ isCherryPickResolved = true;
+ mergeRepository = repo;
+ }
}
if (amendAllowed)
loadPreviousCommit(repos[0]);
@@ -206,7 +211,7 @@ public class CommitUI {
commitDialog.setPreselectedFiles(getSelectedFiles());
commitDialog.setAuthor(author);
commitDialog.setCommitter(committer);
- commitDialog.setAllowToChangeSelection(!isMergedResolved);
+ commitDialog.setAllowToChangeSelection(!isMergedResolved && !isCherryPickResolved);
if (previousCommit != null) {
commitDialog.setPreviousCommitMessage(previousCommit.getFullMessage());
@@ -214,10 +219,14 @@ public class CommitUI {
commitDialog.setPreviousAuthor(previousAuthor.getName()
+ " <" + previousAuthor.getEmailAddress() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
}
- if (isMergedResolved) {
+ if (isMergedResolved || isCherryPickResolved) {
commitDialog.setCommitMessage(getMergeResolveMessage(mergeRepository));
}
+ if (isCherryPickResolved) {
+ commitDialog.setAuthor(getCherryPickOriginalAuthor(mergeRepository));
+ }
+
if (commitDialog.open() != IDialogConstants.OK_ID)
return;
@@ -456,6 +465,18 @@ public class CommitUI {
}
}
+ private String getCherryPickOriginalAuthor(Repository mergeRepository) {
+ try {
+ ObjectId cherryPickHead = mergeRepository.readCherryPickHead();
+ PersonIdent author = new RevWalk(mergeRepository).parseCommit(cherryPickHead).getAuthorIdent();
+ return author.getName() + " <" + author.getEmailAddress() + ">"; //$NON-NLS-1$//$NON-NLS-2$
+ } catch (IOException e) {
+ Activator.handleError(UIText.CommitAction_errorRetrievingCommit, e,
+ true);
+ throw new IllegalStateException(e);
+ }
+ }
+
private String newLine() {
return System.getProperty("line.separator"); //$NON-NLS-1$
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CherryPickHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CherryPickHandler.java
index 5d8d41e..ef9b329 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CherryPickHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/CherryPickHandler.java
@@ -18,8 +18,10 @@ import org.eclipse.egit.ui.UIText;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.api.CherryPickResult;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.CherryPickResult.CherryPickStatus;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.swt.widgets.Shell;
/**
* Executes the CherryPick
@@ -32,18 +34,25 @@ public class CherryPickHandler extends AbstractHistoryCommandHandler {
CherryPickResult cherryPickResult;
Git git = new Git(repo);
+ Shell parent = getPart(event).getSite().getShell();
try {
cherryPickResult = git.cherryPick().include(commit.getId()).call();
newHead = cherryPickResult.getNewHead();
if (newHead != null && cherryPickResult.getCherryPickedRefs().isEmpty())
- MessageDialog.openWarning(getPart(event).getSite().getShell(),
+ MessageDialog.openWarning(parent,
UIText.CherryPickHandler_NoCherryPickPerformedTitle,
UIText.CherryPickHandler_NoCherryPickPerformedMessage);
} catch (Exception e) {
throw new ExecutionException(UIText.CherryPickOperation_InternalError, e);
}
if (newHead == null)
- throw new ExecutionException(UIText.CherryPickOperation_Failed);
+ if (cherryPickResult.getStatus() == CherryPickStatus.CONFLICTING)
+ MessageDialog.openWarning(parent,
+ UIText.CherryPickHandler_CherryPickConflictsTitle,
+ UIText.CherryPickHandler_CherryPickConflictsMessage);
+ else
+ throw new ExecutionException(UIText.CherryPickOperation_Failed);
+
return null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java
index c4e283c..222ac16 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java
@@ -135,6 +135,8 @@ public class GitMergeEditorInput extends CompareEditorInput {
String target;
if (repo.getRepositoryState().equals(RepositoryState.MERGING))
target = Constants.MERGE_HEAD;
+ else if (repo.getRepositoryState().equals(RepositoryState.CHERRY_PICKING))
+ target = Constants.CHERRY_PICK_HEAD;
else if (repo.getRepositoryState().equals(
RepositoryState.REBASING_INTERACTIVE))
target = readFile(repo.getDirectory(),
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 2657c88..0e452db 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -162,6 +162,8 @@ CheckoutHandler_SelectBranchMessage=There is more than one branch for this commi
CheckoutHandler_SelectBranchTitle=Select a branch for checkout
CherryPickHandler_NoCherryPickPerformedMessage=The change has already been included
CherryPickHandler_NoCherryPickPerformedTitle=No cherry pick performed
+CherryPickHandler_CherryPickConflictsMessage=Cherry pick could not be completed automatically because of conflicts. Please resolve and commit.
+CherryPickHandler_CherryPickConflictsTitle=Cherry Pick Conflicts
CherryPickOperation_Failed=The cherry-pick failed
CherryPickOperation_InternalError=An internal error occurred
CompareTargetSelectionDialog_CompareButton=&Compare