Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit')
-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 04673367a6..3eddf3589b 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 fd02dd06d8..b70238ec97 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 3342410d9a..8a2616c4be 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