Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-02-12 10:18:43 +0000
committerMatthias Sohn2018-02-13 00:16:13 +0000
commitffa3b9913f7de7974e8aa6e5609ee1ab55c4c3fe (patch)
treeff5875fd9c7c1ea5e9a416c5327dc7dcbad97f72 /org.eclipse.egit.ui/src/org/eclipse/egit/ui
parent56bfb4ea9d16b8b73b2d91a47cade016f7596c0b (diff)
downloadegit-ffa3b9913f7de7974e8aa6e5609ee1ab55c4c3fe.tar.gz
egit-ffa3b9913f7de7974e8aa6e5609ee1ab55c4c3fe.tar.xz
egit-ffa3b9913f7de7974e8aa6e5609ee1ab55c4c3fe.zip
Include local branch name in proposals
If "Push branch 'foo'" is run the default suggestion for the upstream name is the configured remote tracking branch (if any). The local branch name is suggested initially only if no remote tracking branch is set. A frequent use case for this dialog is to push a local branch to a *new* remote branch with the same name as the local branch. But since typically local branches are created off 'master' and do have 'origin/master' set as tracking branch, a user has in this case to type in the new upstream branch name. It wouldn't appear in the proposals list, which showed only existing upstream refs. Simplify this use case by including a ref for a new upstream branch in the list of proposals if there is no existing upstream branch with the same name as the local branch. Bug: 530685 Change-Id: I861d0ab73ed9476e664e5fe203da3a84829ce04f Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit/ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousListOperation.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousRefProposalProvider.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefContentProposal.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java40
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties5
7 files changed, 60 insertions, 28 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index a608464580..782f948579 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -143,6 +143,12 @@ public class UIText extends NLS {
public static String AddToIndexCommand_addingFilesFailed;
/** */
+ public static String AsynchronousRefProposalProvider_FetchingRemoteRefsMessage;
+
+ /** */
+ public static String AsynchronousRefProposalProvider_ShowingProposalsJobName;
+
+ /** */
public static String RemoveFromIndexAction_removingFiles;
/** */
@@ -1556,6 +1562,9 @@ public class UIText extends NLS {
public static String RefContentProposal_errorReadingObject;
/** */
+ public static String RefContentProposal_newRemoteObject;
+
+ /** */
public static String RefContentProposal_tag;
/** */
@@ -2855,9 +2864,6 @@ public class UIText extends NLS {
public static String FetchGerritChangePage_CreatingTagTaskName;
/** */
- public static String FetchGerritChangePage_FetchingRemoteRefsMessage;
-
- /** */
public static String FetchGerritChangePage_FetchingTaskName;
/** */
@@ -2885,9 +2891,6 @@ public class UIText extends NLS {
public static String FetchGerritChangePage_PageTitle;
/** */
- public static String FetchGerritChangePage_ShowingProposalsJobName;
-
- /** */
public static String FetchGerritChangePage_SuggestedRefNamePattern;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousListOperation.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousListOperation.java
index d3b9416aa0..d6340840bb 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousListOperation.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousListOperation.java
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.op.ListRemoteOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
+import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.dialogs.CancelableFuture;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -36,8 +37,6 @@ public abstract class AsynchronousListOperation<T>
private final String uriText;
- private final String jobTitle;
-
private ListRemoteOperation listOp;
/**
@@ -47,19 +46,17 @@ public abstract class AsynchronousListOperation<T>
* local repository for which to run the operation
* @param uriText
* upstream URI
- * @param jobTitle
- * of the background job that will execute this
*/
- public AsynchronousListOperation(Repository repository, String uriText,
- String jobTitle) {
+ public AsynchronousListOperation(Repository repository, String uriText) {
this.repository = repository;
this.uriText = uriText;
- this.jobTitle = jobTitle;
}
@Override
protected String getJobTitle() {
- return MessageFormat.format(jobTitle, uriText);
+ return MessageFormat.format(
+ UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage,
+ uriText);
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousRefProposalProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousRefProposalProvider.java
index 6234269e56..e52de02e9e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousRefProposalProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/AsynchronousRefProposalProvider.java
@@ -103,7 +103,7 @@ public class AsynchronousRefProposalProvider
if (!list.isFinished()) {
IRunnableWithProgress operation = monitor -> {
monitor.beginTask(MessageFormat.format(
- UIText.FetchGerritChangePage_FetchingRemoteRefsMessage,
+ UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage,
uri), IProgressMonitor.UNKNOWN);
Collection<Ref> result = list.get();
if (monitor.isCanceled()) {
@@ -116,7 +116,7 @@ public class AsynchronousRefProposalProvider
}
// If we do have results now, open the proposals.
Job showProposals = new WorkbenchJob(
- UIText.FetchGerritChangePage_ShowingProposalsJobName) {
+ UIText.AsynchronousRefProposalProvider_ShowingProposalsJobName) {
@Override
public boolean shouldRun() {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefContentProposal.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefContentProposal.java
index 44213c5837..ad4a3d3139 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefContentProposal.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefContentProposal.java
@@ -136,6 +136,8 @@ public class RefContentProposal implements IContentProposal {
public String getDescription() {
if (objectId == null) {
return null;
+ } else if (upstream && objectId.equals(ObjectId.zeroId())) {
+ return refName + '\n' + UIText.RefContentProposal_newRemoteObject;
}
try (ObjectReader reader = db.newObjectReader()) {
ObjectLoader loader = null;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
index 3f52d3a5cc..cad680e295 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
@@ -765,7 +765,7 @@ public class FetchGerritChangePage extends WizardPage {
IWizardContainer container = getContainer();
IRunnableWithProgress operation = monitor -> {
monitor.beginTask(MessageFormat.format(
- UIText.FetchGerritChangePage_FetchingRemoteRefsMessage,
+ UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage,
uriText), IProgressMonitor.UNKNOWN);
Collection<Change> result = list.get();
if (monitor.isCanceled()) {
@@ -778,7 +778,7 @@ public class FetchGerritChangePage extends WizardPage {
}
// If we do have results now, open the proposals.
Job showProposals = new WorkbenchJob(
- UIText.FetchGerritChangePage_ShowingProposalsJobName) {
+ UIText.AsynchronousRefProposalProvider_ShowingProposalsJobName) {
@Override
public boolean shouldRun() {
@@ -1004,7 +1004,7 @@ public class FetchGerritChangePage extends WizardPage {
throws OperationCanceledException {
if (changeList != null) {
monitor.subTask(NLS.bind(
- UIText.FetchGerritChangePage_FetchingRemoteRefsMessage,
+ UIText.AsynchronousRefProposalProvider_FetchingRemoteRefsMessage,
uri));
Collection<Change> changes;
try {
@@ -1300,8 +1300,7 @@ public class FetchGerritChangePage extends WizardPage {
private static class ChangeList extends AsynchronousListOperation<Change> {
public ChangeList(Repository repository, String uriText) {
- super(repository, uriText,
- UIText.FetchGerritChangePage_FetchingRemoteRefsMessage);
+ super(repository, uriText);
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java
index 39d7fb8715..6ca9b14e42 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushBranchPage.java
@@ -50,7 +50,9 @@ import org.eclipse.jgit.lib.BranchConfig;
import org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -316,7 +318,8 @@ public class PushBranchPage extends WizardPage {
}, uri -> {
FutureRefs list = refs.get(uri);
if (list == null) {
- list = new FutureRefs(repository, uri);
+ list = new FutureRefs(repository, uri,
+ getLocalBranchName());
refs.put(uri, list);
}
return list;
@@ -491,6 +494,13 @@ public class PushBranchPage extends WizardPage {
}
}
+ private String getLocalBranchName() {
+ if (ref != null && !ref.getName().startsWith(Constants.R_REMOTES)) {
+ return Repository.shortenRefName(ref.getName());
+ }
+ return null;
+ }
+
private String getSuggestedBranchName() {
if (ref != null && !ref.getName().startsWith(Constants.R_REMOTES)) {
StoredConfig config = repository.getConfig();
@@ -513,7 +523,8 @@ public class PushBranchPage extends WizardPage {
String uriText = config.getURIs().get(0).toString();
FutureRefs list = refs.get(uriText);
if (list == null) {
- list = new FutureRefs(repository, uriText);
+ list = new FutureRefs(repository, uriText,
+ getLocalBranchName());
refs.put(uriText, list);
preFetch(list);
}
@@ -569,23 +580,42 @@ public class PushBranchPage extends WizardPage {
*/
private static class FutureRefs extends AsynchronousListOperation<Ref> {
- public FutureRefs(Repository repository, String uriText) {
- super(repository, uriText,
- UIText.FetchGerritChangePage_FetchingRemoteRefsMessage);
+ private final String localBranchName;
+
+ public FutureRefs(Repository repository, String uriText,
+ String localBranchName) {
+ super(repository, uriText);
+ this.localBranchName = localBranchName;
}
@Override
protected Collection<Ref> convert(Collection<Ref> refs) {
List<Ref> filtered = new ArrayList<>();
+ String localFullName = localBranchName != null
+ ? Constants.R_HEADS + localBranchName : null;
+ boolean localBranchFound = false;
// Restrict to branches
for (Ref ref : refs) {
String name = ref.getName();
if (name.startsWith(Constants.R_HEADS)) {
filtered.add(ref);
+ if (localFullName != null
+ && localFullName.equalsIgnoreCase(name)) {
+ localBranchFound = true;
+ }
}
}
// Sort them
Collections.sort(filtered, CommonUtils.REF_ASCENDING_COMPARATOR);
+ // Add a new remote ref for localBranchName in front if it doesn't
+ // exist
+ if (localFullName != null && !localBranchFound) {
+ List<Ref> newRefs = new ArrayList<>(filtered.size() + 1);
+ newRefs.add(new ObjectIdRef.Unpeeled(Storage.NEW, localFullName,
+ ObjectId.zeroId()));
+ newRefs.addAll(filtered);
+ filtered = newRefs;
+ }
return filtered;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 29e2c0f579..9d37794af5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -56,6 +56,8 @@ AddRemoteWizard_Title=Add Remote
AddSubmoduleWizard_WindowTitle=Add Submodule
AddToIndexAction_addingFiles=Adding Files to Index
AddToIndexCommand_addingFilesFailed=Adding files failed
+AsynchronousRefProposalProvider_FetchingRemoteRefsMessage=Fetching remote refs from {0}
+AsynchronousRefProposalProvider_ShowingProposalsJobName=Showing proposals
RemoveFromIndexAction_removingFiles=Removing file from Index
BlameInformationControl_Author=Author: {0} <{1}> {2}
BlameInformationControl_Commit=Commit {0}
@@ -538,6 +540,7 @@ RefContentProposal_branch=branch
RefContentProposal_by=by
RefContentProposal_commit=commit
RefContentProposal_errorReadingObject=Unable to read object {0} for content proposal assistance (ref = {1})
+RefContentProposal_newRemoteObject=New object will be created at the remote repository
RefContentProposal_tag=tag
RefContentProposal_trackingBranch=tracking branch
RefContentProposal_tree=tree
@@ -961,7 +964,6 @@ FetchGerritChangePage_ContentAssistDescription=Patch set {0} of change {1}
FetchGerritChangePage_ContentAssistTooltip=Press {0} to see a filtered list of changes
FetchGerritChangePage_CreatingBranchTaskName=Creating branch
FetchGerritChangePage_CreatingTagTaskName=Creating tag
-FetchGerritChangePage_FetchingRemoteRefsMessage=Fetching remote refs from {0}
FetchGerritChangePage_FetchingTaskName=Fetching change {0}
FetchGerritChangePage_GeneratedTagMessage=Generated for Gerrit change {0}
FetchGerritChangePage_GetChangeTaskName=Get change from Gerrit
@@ -971,7 +973,6 @@ FetchGerritChangePage_MissingChangeMessage=Please provide a change
FetchGerritChangePage_NoSuchChangeMessage=The Gerrit server has no change number {0}
FetchGerritChangePage_PageMessage=Please select a Gerrit URI and change to fetch
FetchGerritChangePage_PageTitle=Fetch a change from Gerrit into repository {0}
-FetchGerritChangePage_ShowingProposalsJobName=Showing proposals
FetchGerritChangePage_SuggestedRefNamePattern=change/{0}/{1}
FetchGerritChangePage_TagNameText=Tag &name:
FetchGerritChangePage_TagRadio=Create and check out a &tag

Back to the top