diff options
author | André Dietisheim | 2012-09-06 12:33:59 +0000 |
---|---|---|
committer | Matthias Sohn | 2012-10-27 22:11:54 +0000 |
commit | f7ee043036daad6d4b176eb608767e53f5bdfa48 (patch) | |
tree | dcfb0b999ae11d24d30a7e379e6a20afd712a9ac /org.eclipse.egit.ui/src/org | |
parent | cb5822257614b5d6b814d5d43c6b5193aeb87637 (diff) | |
download | egit-f7ee043036daad6d4b176eb608767e53f5bdfa48.tar.gz egit-f7ee043036daad6d4b176eb608767e53f5bdfa48.tar.xz egit-f7ee043036daad6d4b176eb608767e53f5bdfa48.zip |
Allow users to push to upstream when committing in the staging view
I added 2 new buttons to the form, that allow the user to commit
and to commit + push changes upstream in a single step.
The push occurs either to the default remote or to the user
configured push (via push configuration dialog).
Bug: 388913
Change-Id: I1d6cc6436c6d35f24f01066865dcfe1ca48557b3
Signed-off-by: Andre Dietisheim <adietish@redhat.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui/src/org')
5 files changed, 236 insertions, 145 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 1a24ac744f..0e8cebbc43 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 @@ -4450,6 +4450,9 @@ public class UIText extends NLS { public static String StagingView_CommitMessage; /** */ + public static String StagingView_CommitAndPush; + + /** */ public static String StagingView_Committer; /** */ 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 new file mode 100644 index 0000000000..923c870b6b --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitJob.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. Distributed under license by Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andre Dietisheim - initial API and implementation + *******************************************************************************/ + +package org.eclipse.egit.ui.internal.commit; + +import java.net.URISyntaxException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.egit.core.op.CommitOperation; +import org.eclipse.egit.core.project.RepositoryMapping; +import org.eclipse.egit.ui.Activator; +import org.eclipse.egit.ui.JobFamilies; +import org.eclipse.egit.ui.UIPreferences; +import org.eclipse.egit.ui.UIText; +import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator; +import org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager; +import org.eclipse.egit.ui.internal.push.PushOperationUI; +import org.eclipse.egit.ui.internal.push.PushWizard; +import org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.jgit.api.errors.JGitInternalException; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.transport.RemoteConfig; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * Executes a given commit operation on a given repository. Will also eventually + * show the commit that was performed and push the repository upstream. + */ +public class CommitJob extends Job { + + private CommitOperation commitOperation; + + private Repository repository; + + private boolean openCommitEditor; + + private boolean pushUpstream; + + /** + * @param repository + * the repository to commit to + * @param commitOperation + * the commit operation to use + * + */ + public CommitJob(final Repository repository, + final CommitOperation commitOperation) { + super(UIText.CommitAction_CommittingChanges); + this.repository = repository; + this.commitOperation = commitOperation; + } + + /** + * Sets this job to open the commit editor after committing. + * + * @param openCommitEditor + * @return this job instance + */ + public CommitJob setOpenCommitEditor(boolean openCommitEditor) { + this.openCommitEditor = openCommitEditor; + return this; + } + + /** + * Sets this job to push the changes upstream after successfully committing. + * @param pushUpstream + * @return this commit job instance + */ + public CommitJob setPushUpstream(boolean pushUpstream) { + this.pushUpstream = pushUpstream; + return this; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + RevCommit commit = null; + try { + commitOperation.execute(monitor); + commit = commitOperation.getCommit(); + CommitMessageComponentStateManager.deleteState(repository); + RepositoryMapping mapping = RepositoryMapping + .findRepositoryMapping(repository); + if (mapping != null) + mapping.fireRepositoryChanged(); + } catch (CoreException e) { + if (e.getCause() instanceof JGitInternalException) + return Activator.createErrorStatus(e.getLocalizedMessage(), + e.getCause()); + return Activator.createErrorStatus( + UIText.CommitAction_CommittingFailed, e); + } finally { + GitLightweightDecorator.refresh(); + } + + if (commit != null) { + if (openCommitEditor) + openCommitEditor(commit); + if (pushUpstream) + pushUpstream(); + } + return Status.OK_STATUS; + } + + private void openCommitEditor(final RevCommit newCommit) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + + public void run() { + CommitEditor.openQuiet(new RepositoryCommit(repository, + newCommit)); + } + }); + } + + private void pushUpstream() { + RemoteConfig config = SimpleConfigurePushDialog + .getConfiguredRemote(repository); + if (config == null) { + final Display display = Display.getDefault(); + display.asyncExec(new Runnable() { + + public void run() { + try { + WizardDialog wizardDialog = new WizardDialog(display + .getActiveShell(), new PushWizard(repository)); + wizardDialog.setHelpAvailable(true); + wizardDialog.open(); + } catch (URISyntaxException e) { + Activator.handleError( + NLS.bind(UIText.CommitUI_pushFailedMessage, e), + e, true); + } + } + }); + } else { + int timeout = Activator.getDefault().getPreferenceStore() + .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); + PushOperationUI op = new PushOperationUI(repository, + config.getName(), timeout, false); + op.start(); + } + + } + + @Override + public boolean belongsTo(Object family) { + if (family.equals(JobFamilies.COMMIT)) + return true; + return super.belongsTo(family); + } + +} 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 19e85e9c45..4c2c241a33 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 @@ -20,7 +20,6 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URI; -import java.net.URISyntaxException; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; @@ -33,40 +32,24 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.egit.core.EclipseGitProgressTransformer; import org.eclipse.egit.core.IteratorService; import org.eclipse.egit.core.op.CommitOperation; import org.eclipse.egit.core.project.RepositoryMapping; import org.eclipse.egit.ui.Activator; -import org.eclipse.egit.ui.JobFamilies; -import org.eclipse.egit.ui.UIPreferences; import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.UIUtils; -import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator; import org.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog; import org.eclipse.egit.ui.internal.dialogs.CommitDialog; -import org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager; -import org.eclipse.egit.ui.internal.push.PushOperationUI; -import org.eclipse.egit.ui.internal.push.PushWizard; -import org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.IndexDiff; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; @@ -211,116 +194,13 @@ public class CommitUI { commitOperation.setCommitAll(commitHelper.isMergedResolved); if (commitHelper.isMergedResolved) commitOperation.setRepository(repo); - Job commitJob = createCommitJob(repo, commitOperation, false); - if (commitDialog.isPushRequested()) - pushWhenFinished(commitJob); - + Job commitJob = new CommitJob(repo, commitOperation). + setPushUpstream(commitDialog.isPushRequested()); commitJob.schedule(); return true; } - private void pushWhenFinished(Job commitJob) { - commitJob.addJobChangeListener(new JobChangeAdapter() { - - @Override - public void done(IJobChangeEvent event) { - if (event.getResult().getSeverity() == IStatus.ERROR) - return; - RemoteConfig config = SimpleConfigurePushDialog - .getConfiguredRemote(repo); - if (config == null) { - Display.getDefault().syncExec(new Runnable() { - - public void run() { - try { - WizardDialog wizardDialog = new WizardDialog( - shell, new PushWizard(repo)); - wizardDialog.setHelpAvailable(true); - wizardDialog.open(); - } catch (URISyntaxException e) { - Activator.handleError(NLS.bind( - UIText.CommitUI_pushFailedMessage, e), - e, true); - } - } - }); - } else { - int timeout = Activator.getDefault().getPreferenceStore() - .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); - PushOperationUI op = new PushOperationUI(repo, config - .getName(), timeout, false); - op.start(); - } - } - }); - } - - /** - * Uses a Job to perform the given CommitOperation - * @param repository - * @param commitOperation - * @param openNewCommit - */ - public static void performCommit(final Repository repository, - final CommitOperation commitOperation, final boolean openNewCommit) { - Job job = createCommitJob(repository, commitOperation, openNewCommit); - job.schedule(); - } - - private static Job createCommitJob(final Repository repository, - final CommitOperation commitOperation, final boolean openNewCommit) { - String jobname = UIText.CommitAction_CommittingChanges; - Job job = new Job(jobname) { - @Override - protected IStatus run(IProgressMonitor monitor) { - RevCommit commit = null; - try { - commitOperation.execute(monitor); - commit = commitOperation.getCommit(); - CommitMessageComponentStateManager.deleteState( - repository); - RepositoryMapping mapping = RepositoryMapping - .findRepositoryMapping(repository); - if (mapping != null) - mapping.fireRepositoryChanged(); - } catch (CoreException e) { - if (e.getCause() instanceof JGitInternalException) - return Activator.createErrorStatus( - e.getLocalizedMessage(), e.getCause()); - return Activator.createErrorStatus( - UIText.CommitAction_CommittingFailed, e); - } finally { - GitLightweightDecorator.refresh(); - } - if (openNewCommit && commit != null) - openCommit(repository, commit); - return Status.OK_STATUS; - } - - @Override - public boolean belongsTo(Object family) { - if (family.equals(JobFamilies.COMMIT)) - return true; - return super.belongsTo(family); - } - - }; - job.setUser(true); - return job; - } - - private static void openCommit(final Repository repository, - final RevCommit newCommit) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - - public void run() { - CommitEditor.openQuiet(new RepositoryCommit(repository, - newCommit)); - } - }); - } - private IProject[] getProjectsOfRepositories() { Set<IProject> ret = new HashSet<IProject>(); final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot() 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 bd92964f46..4e875fe645 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 @@ -33,6 +33,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.core.runtime.preferences.InstanceScope; @@ -51,9 +52,9 @@ import org.eclipse.egit.ui.internal.EgitUiEditorUtils; import org.eclipse.egit.ui.internal.actions.ActionCommands; import org.eclipse.egit.ui.internal.actions.BooleanPrefAction; 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.CommitUI; import org.eclipse.egit.ui.internal.components.ToggleableWarningLabel; import org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator; import org.eclipse.egit.ui.internal.dialogs.CommitMessageArea; @@ -124,10 +125,14 @@ import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; @@ -185,8 +190,6 @@ public class StagingView extends ViewPart { private Text authorText; - private Action commitAction; - private CommitMessageComponent commitMessageComponent; private boolean reactOnSelection = true; @@ -302,6 +305,10 @@ public class StagingView extends ViewPart { private UndoRedoActionGroup undoRedoActionGroup; + private Button commitButton; + + private Button commitAndPushButton; + @Override public void createPartControl(Composite parent) { GridLayoutFactory.fillDefaults().applyTo(parent); @@ -457,6 +464,42 @@ public class StagingView extends ViewPart { committerText.setLayoutData(GridDataFactory.fillDefaults() .grab(true, false).create()); + Composite buttonsContainer = toolkit.createComposite(composite); + GridDataFactory.fillDefaults().grab(true, false).span(2,1).indent(0, 8) + .applyTo(buttonsContainer); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(buttonsContainer); + + Label filler = toolkit.createLabel(buttonsContainer, ""); //$NON-NLS-1$ + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(filler); + + Composite commitButtonsContainer = toolkit.createComposite(buttonsContainer); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER) + .applyTo(commitButtonsContainer); + GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(commitButtonsContainer); + + this.commitAndPushButton = toolkit.createButton(commitButtonsContainer, + UIText.StagingView_CommitAndPush, SWT.PUSH); + commitAndPushButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + commit(true); + } + }); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER) + .applyTo(commitAndPushButton); + + this.commitButton = toolkit.createButton(commitButtonsContainer, + UIText.StagingView_Commit, SWT.PUSH); + + commitButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + commit(false); + } + }); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER) + .applyTo(commitButton); + stagedSection = toolkit.createSection(stagingSashForm, ExpandableComposite.TITLE_BAR); Composite stagedTableComposite = toolkit.createComposite(stagedSection); @@ -555,7 +598,7 @@ public class StagingView extends ViewPart { public void verifyKey(VerifyEvent event) { if (UIUtils.isSubmitKeyEvent(event)) { event.doit = false; - commit(); + commit(false); } } }); @@ -563,13 +606,14 @@ public class StagingView extends ViewPart { commitMessageText.getTextWidget().addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { // Ctrl+Enter shortcut only works when the focus is on the commit message text - commitAction.setToolTipText(MessageFormat.format( + String commitButtonTooltip = MessageFormat.format( UIText.StagingView_CommitToolTip, - UIUtils.SUBMIT_KEY_STROKE.format())); + UIUtils.SUBMIT_KEY_STROKE.format()); + commitButton.setToolTipText(commitButtonTooltip); } public void focusLost(FocusEvent e) { - commitAction.setToolTipText(null); + commitButton.setToolTipText(null); } }); @@ -621,7 +665,8 @@ public class StagingView extends ViewPart { amendPreviousCommitAction.setEnabled(enabled); signedOffByAction.setEnabled(enabled); addChangeIdAction.setEnabled(enabled); - commitAction.setEnabled(enabled); + commitButton.setEnabled(enabled); + commitAndPushButton.setEnabled(enabled); } private void updateToolbar() { @@ -685,15 +730,6 @@ public class StagingView extends ViewPart { toolbar.add(new Separator()); - commitAction = new Action(UIText.StagingView_Commit, - IAction.AS_PUSH_BUTTON) { - public void run() { - commit(); - } - }; - commitAction.setImageDescriptor(UIIcons.COMMIT); - toolbar.add(commitAction); - openNewCommitsAction = new Action(UIText.StagingView_OpenNewCommits, IAction.AS_CHECK_BOX) { @@ -1326,8 +1362,10 @@ public class StagingView extends ViewPart { unstagedTableViewer.setInput(update); stagedTableViewer.setInput(update); enableCommitWidgets(indexDiffAvailable); - commitAction.setEnabled(indexDiffAvailable && repository.getRepositoryState() - .canCommit()); + boolean commitEnabled = + indexDiffAvailable && repository.getRepositoryState().canCommit(); + commitButton.setEnabled(commitEnabled); + commitAndPushButton.setEnabled(commitEnabled); form.setText(StagingView.getRepositoryName(repository)); updateCommitMessageComponent(repositoryChanged, indexDiffAvailable); updateSectionText(); @@ -1511,7 +1549,7 @@ public class StagingView extends ViewPart { return files; } - private void commit() { + private void commit(boolean pushUpstream) { if (!isCommitWithoutFilesAllowed()) { MessageDialog.openError(getSite().getShell(), UIText.StagingView_committingNotPossible, @@ -1538,8 +1576,10 @@ public class StagingView extends ViewPart { if (amendPreviousCommitAction.isChecked()) commitOperation.setAmending(true); commitOperation.setComputeChangeId(addChangeIdAction.isChecked()); - CommitUI.performCommit(currentRepository, commitOperation, - openNewCommitsAction.isChecked()); + Job commitJob = new CommitJob(currentRepository, commitOperation) + .setOpenCommitEditor(openNewCommitsAction.isChecked()) + .setPushUpstream(pushUpstream); + commitJob.schedule(); CommitMessageHistory.saveCommitHistory(commitMessage); clearCommitMessageToggles(); commitMessageText.setText(EMPTY_STRING); 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 84b37540b6..a08c45ef8d 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 @@ -1559,8 +1559,9 @@ StagingView_Author=Author: StagingView_Ammend_Previous_Commit=Amend Previous Commit StagingView_Add_Signed_Off_By=Add Signed-off-by StagingView_Add_Change_ID=Add Change-Id -StagingView_Commit=Commit +StagingView_Commit=&Commit StagingView_CommitToolTip=Commit ({0}) +StagingView_CommitAndPush=Commit and &Push StagingView_checkoutFailed=Checking out files failed StagingView_commitFailed=Commit failed StagingView_committingNotPossible=Committing is not possible |