Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2012-09-02 17:37:25 -0400
committerMatthias Sohn2012-09-02 17:37:25 -0400
commit03513ef305f3d4f8414ab7ac2624b6d2ca75b3ee (patch)
tree81abe7c1c899ebd935350eafb5791fbf5a156c3a /org.eclipse.egit.ui/src/org/eclipse
parentfa2f9bf5afb9e111f496acd42dcca2696b0120fc (diff)
downloadegit-03513ef305f3d4f8414ab7ac2624b6d2ca75b3ee.tar.gz
egit-03513ef305f3d4f8414ab7ac2624b6d2ca75b3ee.tar.xz
egit-03513ef305f3d4f8414ab7ac2624b6d2ca75b3ee.zip
[historyView] Rebase: Pass a better Ref as upstream
JGit change I1333a8dd170bb0077f491962013485efb6f2a926 is about improving the ours/theirs conflict markers during rebase. The way the rebase action worked before, it would always pass the commit ID to rebase, which is not very helpful during a rebase conflict. This change makes it use a Ref if there is one. If there are multiple refs pointing to the selected commit: - and if the branch being rebased tracks another one, this tracked branch should be the one to pick if it's in the list - otherwise pick a remote tracking branch if it's in the list Also adds a "does it work at all?" test for rebase in History view. Bug: 336819 Change-Id: Ib78c3e8965e2f57e2c844a065629511ab1158160 Signed-off-by: Robin Stocker <robin@nibor.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseCurrentHandler.java52
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties1
3 files changed, 50 insertions, 6 deletions
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 04673367a..3eddf3589 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
@@ -675,6 +675,9 @@ public class UIText extends NLS {
public static String RebaseCurrentRefCommand_RebasingCurrentJobName;
/** */
+ public static String RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage;
+
+ /** */
public static String RebaseResultDialog_Aborted;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseCurrentHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseCurrentHandler.java
index fd02dd06d..b70238ec9 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseCurrentHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/RebaseCurrentHandler.java
@@ -13,14 +13,19 @@
package org.eclipse.egit.ui.internal.history.command;
+import java.io.IOException;
+
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.rebase.RebaseHelper;
+import org.eclipse.jgit.lib.BranchConfig;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectIdRef;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Ref.Storage;
-import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revplot.PlotCommit;
import org.eclipse.osgi.util.NLS;
/**
@@ -30,17 +35,52 @@ public class RebaseCurrentHandler extends AbstractHistoryCommandHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
- RevCommit commit = (RevCommit) getSelection(getPage()).getFirstElement();
+ PlotCommit commit = (PlotCommit) getSelection(getPage()).getFirstElement();
final Repository repository = getRepository(event);
if (repository == null)
return null;
+ String currentBranch = getCurrentBranch(repository);
+ Ref ref = getRef(commit, repository, currentBranch);
+
String jobname = NLS.bind(
- UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, commit);
- RebaseHelper.runRebaseJob(repository, jobname,
- new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(),
- commit));
+ UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, currentBranch);
+ RebaseHelper.runRebaseJob(repository, jobname, ref);
return null;
}
+ private Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
+ int count = commit.getRefCount();
+ if (count == 0)
+ return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
+ else if (count == 1)
+ return commit.getRef(0);
+ else {
+ BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
+ String trackingBranch = branchConfig.getTrackingBranch();
+ Ref remoteRef = null;
+
+ for (int i = 0; i < count; i++) {
+ Ref ref = commit.getRef(i);
+ if (trackingBranch != null && trackingBranch.equals(ref.getName()))
+ return ref;
+ if (ref.getName().startsWith(Constants.R_REMOTES))
+ remoteRef = ref;
+ }
+
+ if (remoteRef != null)
+ return remoteRef;
+ else
+ // We tried to pick a nice ref, just pick the first then
+ return commit.getRef(0);
+ }
+ }
+
+ private String getCurrentBranch(Repository repository) throws ExecutionException {
+ try {
+ return repository.getBranch();
+ } catch (IOException e) {
+ throw new ExecutionException(UIText.RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage, e);
+ }
+ }
}
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 3342410d9..8a2616c4b 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
@@ -281,6 +281,7 @@ CompareWithIndexAction_FileNotInIndex={0} not in index
RebaseCurrentRefCommand_RebaseCanceledMessage=The rebase operation was canceled
RebaseCurrentRefCommand_RebaseCanceledTitle=Rebase Canceled
RebaseCurrentRefCommand_RebasingCurrentJobName=Rebasing Branch {0}
+RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage=Error getting the branch to rebase
RebaseResultDialog_Aborted=Rebase was aborted
RebaseResultDialog_AbortRebaseRadioText=&Abort rebase
RebaseResultDialog_ActionGroupTitle=Action to perform

Back to the top