diff options
author | Frank Jakop | 2015-10-13 11:39:58 +0000 |
---|---|---|
committer | Matthias Sohn | 2016-02-21 01:16:28 +0000 |
commit | af5c88dc1ce31f1d8ee5890b75242f40b4d87a3d (patch) | |
tree | 86da0caf52c58e0401e20730210fc1369ecd6f94 | |
parent | 6ee2f439c43c52ff4a8f79bf3f2e4977bc41d5e2 (diff) | |
download | egit-af5c88dc1ce31f1d8ee5890b75242f40b4d87a3d.tar.gz egit-af5c88dc1ce31f1d8ee5890b75242f40b4d87a3d.tar.xz egit-af5c88dc1ce31f1d8ee5890b75242f40b4d87a3d.zip |
Gerrit Configuration... is misleading when switching branches
Treat "Commit and Push" as Gerrit push for the currently checked out
branch when the repository has a gerrit configuration.
Bug: 460500
Change-Id: I6eddab11e58a383cd7a9ebe11226f344e97aa324
Signed-off-by: Frank Jakop <frank.jakop@arxes-tolina.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
4 files changed, 96 insertions, 42 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java index 6f85f6f7a7..04c5330181 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java @@ -28,8 +28,11 @@ import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator; import org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager; import org.eclipse.egit.ui.internal.push.PushBranchWizard; import org.eclipse.egit.ui.internal.push.PushOperationUI; +import org.eclipse.egit.ui.internal.push.PushToGerritWizard; +import org.eclipse.egit.ui.internal.push.PushWizard; import org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jgit.api.errors.AbortedByHookException; import org.eclipse.jgit.api.errors.JGitInternalException; @@ -54,7 +57,17 @@ public class CommitJob extends Job { private boolean openCommitEditor; - private boolean pushUpstream; + private PushMode pushMode; + + /** + * where to push changes + */ + public enum PushMode { + /** use {@link PushWizard} */ + UPSTREAM, + /** use {@link PushToGerritWizard} */ + GERRIT; + } /** * @param repository @@ -83,11 +96,12 @@ public class CommitJob extends Job { /** * Sets this job to push the changes upstream after successfully committing. - * @param pushUpstream + * + * @param pushMode * @return this commit job instance */ - public CommitJob setPushUpstream(boolean pushUpstream) { - this.pushUpstream = pushUpstream; + public CommitJob setPushUpstream(final PushMode pushMode) { + this.pushMode = pushMode; return this; } @@ -119,10 +133,12 @@ public class CommitJob extends Job { } if (commit != null) { - if (openCommitEditor) + if (openCommitEditor) { openCommitEditor(commit); - if (pushUpstream) - pushUpstream(commit); + } + if (pushMode != null) { + pushUpstream(commit, pushMode); + } } return Status.OK_STATUS; } @@ -151,43 +167,50 @@ public class CommitJob extends Job { }); } - private void pushUpstream(final RevCommit commit) { + private void pushUpstream(final RevCommit commit, final PushMode pushTo) { RemoteConfig config = SimpleConfigurePushDialog .getConfiguredRemote(repository); - if (config == null) { - final Display display = Display.getDefault(); - display.asyncExec(new Runnable() { - - @Override - public void run() { - try { - PushBranchWizard pushWizard = null; - String fullBranch = repository.getFullBranch(); - if (fullBranch != null - && fullBranch.startsWith(Constants.R_HEADS)) { - Ref ref = repository.getRef(fullBranch); - pushWizard = new PushBranchWizard(repository, ref); - } else { - pushWizard = new PushBranchWizard(repository, - commit.getId()); - } - WizardDialog wizardDialog = new WizardDialog(display - .getActiveShell(), pushWizard); - wizardDialog.setHelpAvailable(true); - wizardDialog.open(); - } catch (IOException e) { - Activator.handleError( - NLS.bind(UIText.CommitUI_pushFailedMessage, e), - e, true); - } + + if (pushTo == PushMode.GERRIT) { + final Wizard pushWizard = new PushToGerritWizard(repository); + openPushWizard(pushWizard); + } else if (config == null) { + try { + Wizard pushWizard = null; + String fullBranch = repository.getFullBranch(); + if (fullBranch != null + && fullBranch.startsWith(Constants.R_HEADS)) { + Ref ref = repository.getRef(fullBranch); + pushWizard = new PushBranchWizard(repository, ref); + } else { + pushWizard = new PushBranchWizard(repository, + commit.getId()); } - }); + openPushWizard(pushWizard); + } catch (IOException e) { + Activator.handleError( + NLS.bind(UIText.CommitUI_pushFailedMessage, e), e, + true); + } } else { PushOperationUI op = new PushOperationUI(repository, config.getName(), false); op.start(); } + } + private void openPushWizard(final Wizard pushWizard) { + final Display display = Display.getDefault(); + display.asyncExec(new Runnable() { + + @Override + public void run() { + WizardDialog wizardDialog = new WizardDialog(display + .getActiveShell(), pushWizard); + wizardDialog.setHelpAvailable(true); + wizardDialog.open(); + } + }); } @Override 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 3bb98e36a5..02712356e9 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 @@ -42,6 +42,7 @@ import org.eclipse.egit.core.project.RepositoryMapping; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIUtils; import org.eclipse.egit.ui.internal.UIText; +import org.eclipse.egit.ui.internal.commit.CommitJob.PushMode; import org.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog; import org.eclipse.egit.ui.internal.dialogs.CommitDialog; import org.eclipse.jface.dialogs.IDialogConstants; @@ -193,12 +194,20 @@ public class CommitUI { } if (commitDialog.isAmending()) commitOperation.setAmending(true); - commitOperation.setComputeChangeId(commitDialog.getCreateChangeId()); + + final boolean gerritMode = commitDialog.getCreateChangeId(); + + PushMode pushMode = null; + if (commitDialog.isPushRequested()) { + pushMode = gerritMode ? PushMode.GERRIT : PushMode.UPSTREAM; + } + + commitOperation.setComputeChangeId(gerritMode); commitOperation.setCommitAll(commitHelper.isMergedResolved); if (commitHelper.isMergedResolved) commitOperation.setRepository(repo); - Job commitJob = new CommitJob(repo, commitOperation). - setPushUpstream(commitDialog.isPushRequested()); + Job commitJob = new CommitJob(repo, commitOperation) + .setPushUpstream(pushMode); commitJob.schedule(); return true; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java index c50bf70953..eef51f86e1 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java @@ -42,6 +42,7 @@ import org.eclipse.jface.fieldassist.TextContentAdapter; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.jgit.lib.BranchConfig; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; @@ -202,8 +203,20 @@ class PushToGerritPage extends WizardPage { private void setLastUsedBranch() { String lastBranch = settings.get(lastBranchKey); - if (lastBranch != null) + try { + // use upstream if the current branch is tracking a branch + final BranchConfig branchConfig = new BranchConfig( + repository.getConfig(), repository.getBranch()); + final String trackedBranch = branchConfig.getMerge(); + if (trackedBranch != null) { + lastBranch = trackedBranch.replace(Constants.R_HEADS, ""); //$NON-NLS-1$ + } + } catch (final IOException e) { + throw new RuntimeException(e); + } + if (lastBranch != null) { branchText.setText(lastBranch); + } } private void checkPage() { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java index bbef1a13c1..c6d6bddba7 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java @@ -76,6 +76,7 @@ import org.eclipse.egit.ui.internal.commit.CommitHelper; import org.eclipse.egit.ui.internal.commit.CommitJob; import org.eclipse.egit.ui.internal.commit.CommitMessageHistory; import org.eclipse.egit.ui.internal.commit.CommitProposalProcessor; +import org.eclipse.egit.ui.internal.commit.CommitJob.PushMode; import org.eclipse.egit.ui.internal.components.ToggleableWarningLabel; import org.eclipse.egit.ui.internal.decorators.IProblemDecoratable; import org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator; @@ -1059,6 +1060,8 @@ public class StagingView extends ViewPart implements IShowInSource { @Override public void updateChangeIdToggleSelection(boolean selection) { addChangeIdAction.setChecked(selection); + commitAndPushButton + .setImage(selection ? getImage(UIIcons.GERRIT) : null); } @Override @@ -3206,10 +3209,16 @@ public class StagingView extends ViewPart implements IShowInSource { } if (amendPreviousCommitAction.isChecked()) commitOperation.setAmending(true); - commitOperation.setComputeChangeId(addChangeIdAction.isChecked()); + final boolean gerritMode = addChangeIdAction.isChecked(); + commitOperation.setComputeChangeId(gerritMode); + + PushMode pushMode = null; + if (pushUpstream) { + pushMode = gerritMode ? PushMode.GERRIT : PushMode.UPSTREAM; + } final Job commitJob = new CommitJob(currentRepository, commitOperation) - .setOpenCommitEditor(openNewCommitsAction.isChecked()) - .setPushUpstream(pushUpstream); + .setOpenCommitEditor(openNewCommitsAction.isChecked()) + .setPushUpstream(pushMode); // don't allow to do anything as long as commit is in progress enableAllWidgets(false); |