Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Nowak2015-08-27 06:51:59 -0400
committerMatthias Sohn2015-09-11 19:35:17 -0400
commitc575f5b76fe2937ecaed8dbe45da62eee3a737e1 (patch)
treee7aa2b9dded821f61bea08b344aa5a8b6eba6b12
parent189356ba819ea2be0e4e4a40d5b54ba541b1e05a (diff)
downloadegit-c575f5b76fe2937ecaed8dbe45da62eee3a737e1.tar.gz
egit-c575f5b76fe2937ecaed8dbe45da62eee3a737e1.tar.xz
egit-c575f5b76fe2937ecaed8dbe45da62eee3a737e1.zip
Add check for warnings and errors before commit
- Add optional check for warnings and errors before commit which can be configured in preferences - Allow to configure if and when a warning should be displayed and if warnings/errors should block the commit - Add a flag to the staging view which allows to override blocking ad-hoc for the next commit Bug: 475559 Change-Id: I352c33d0fed1b610babda2992c6b1b211952dfb2 Signed-off-by: Pawel Nowak <siersciotluk@gmail.com> Signed-off-by: Andrey Loskutov <loskutov@gmx.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java34
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java106
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/CommittingPreferencePage.java121
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java162
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties11
7 files changed, 410 insertions, 51 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
index a79f48dd0..2de70e0ff 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
@@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.egit.ui;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator;
import org.eclipse.egit.ui.internal.history.FindToolbar;
@@ -25,6 +26,14 @@ import org.eclipse.jface.preference.IPreferenceStore;
*/
public class PluginPreferenceInitializer extends AbstractPreferenceInitializer {
+ /** */
+ public static final String COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_ERRORS = String
+ .valueOf(IMarker.SEVERITY_ERROR);
+
+ /** */
+ public static final String COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_WARNINGS_AND_ERRORS = String
+ .valueOf(IMarker.SEVERITY_WARNING);
+
/**
* Calls super constructor.
*/
@@ -66,6 +75,12 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer {
store.setDefault(UIPreferences.DECORATOR_SHOW_CONFLICTS_ICON, true);
store.setDefault(UIPreferences.DECORATOR_SHOW_ASSUME_VALID_ICON, true);
store.setDefault(UIPreferences.DECORATOR_SHOW_DIRTY_ICON, false);
+ store.setDefault(UIPreferences.WARN_BEFORE_COMMITTING, false);
+ store.setDefault(UIPreferences.WARN_BEFORE_COMMITTING_LEVEL,
+ COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_ERRORS);
+ store.setDefault(UIPreferences.BLOCK_COMMIT, false);
+ store.setDefault(UIPreferences.BLOCK_COMMIT_LEVEL,
+ COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_ERRORS);
w = new int[] { 500, 500 };
store.setDefault(UIPreferences.RESOURCEHISTORY_GRAPH_SPLIT, UIPreferences.intArrayToString(w));
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
index 020a7c4e3..2f86e82b3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
@@ -222,6 +222,18 @@ public class UIPreferences {
/** */
public static final String REBASE_INTERACTIVE_SYNC_SELECTION = "RebaseInteractive_SyncWithSelection"; //$NON-NLS-1$
+ /** */
+ public static final String WARN_BEFORE_COMMITTING = "checkBeforeCommitting"; //$NON-NLS-1$
+
+ /** */
+ public static final String WARN_BEFORE_COMMITTING_LEVEL = "warnBeforeCommitting"; //$NON-NLS-1$
+
+ /** */
+ public static final String BLOCK_COMMIT = "blockCommit"; //$NON-NLS-1$
+
+ /** */
+ public static final String BLOCK_COMMIT_LEVEL = "blockCommitCombo"; //$NON-NLS-1$
+
/**
* Converts a persisted String separated with commas to an integer array
*
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 9fe66a10e..168d2829f 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
@@ -2359,6 +2359,12 @@ public class UIText extends NLS {
public static String CommitDialog_Title;
/** */
+ public static String CommitDialog_IgnoreErrors;
+
+ /** */
+ public static String CommitDialog_MessageErrors;
+
+ /** */
public static String ConfigurationChecker_checkConfiguration;
/** */
@@ -3193,6 +3199,27 @@ public class UIText extends NLS {
public static String CommittingPreferencePage_signedOffByTooltip;
/** */
+ public static String CommittingPreferencePage_CheckBeforeCommitting;
+
+ /** */
+ public static String CommittingPreferencePage_WarnBeforeCommitting;
+
+ /** */
+ public static String CommittingPreferencePage_WarnBeforeCommittingTitle;
+
+ /** */
+ public static String CommittingPreferencePage_WarnBlock_Errors;
+
+ /** */
+ public static String CommittingPreferencePage_WarnBlock_WarningsAndErrors;
+
+ /** */
+ public static String CommittingPreferencePage_BlockCommit;
+
+ /** */
+ public static String CommittingPreferencePage_BlockCommitCombo;
+
+ /** */
public static String Decorator_exceptionMessage;
/** */
@@ -4185,6 +4212,7 @@ public class UIText extends NLS {
/** */
public static String Header_contextMenu_copy_SHA1;
+
/** */
public static String Header_copy_SHA1_error_title;
@@ -5150,6 +5178,12 @@ public class UIText extends NLS {
public static String StagingViewContentProvider_SubmoduleError;
/** */
+ public static String StagingView_IgnoreErrors;
+
+ /** */
+ public static String StagingView_MessageErrors;
+
+ /** */
public static String StashApplyCommand_applyFailed;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java
index 74d8799da..fa7b92e7d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java
@@ -370,6 +370,8 @@ public class CommitDialog extends TitleAreaDialog {
Button commitAndPushButton;
+ Button ignoreErrors;
+
ArrayList<CommitItem> items = new ArrayList<CommitItem>();
private String commitMessage = null;
@@ -724,7 +726,13 @@ public class CommitDialog extends TitleAreaDialog {
UIUtils.hookDisposal(parent, titleImage);
setTitleImage(titleImage);
setTitle(UIText.CommitDialog_Title);
- setMessage(UIText.CommitDialog_Message, IMessageProvider.INFORMATION);
+ if (ignoreErrors != null) {
+ setMessage(UIText.CommitDialog_MessageErrors,
+ IMessageProvider.WARNING);
+ } else {
+ setMessage(UIText.CommitDialog_Message,
+ IMessageProvider.INFORMATION);
+ }
filesViewer.addCheckStateListener(new ICheckStateListener() {
@@ -794,8 +802,28 @@ public class CommitDialog extends TitleAreaDialog {
.hint(600, 200).grab(true, true).create());
resourcesTree.addSelectionListener(new CommitItemSelectionListener());
-
resourcesTree.setHeaderVisible(true);
+
+ if (getPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING)
+ && getPreferenceStore()
+ .getBoolean(UIPreferences.BLOCK_COMMIT)) {
+ ignoreErrors = new Button(resourcesTreeComposite, SWT.CHECK);
+ ignoreErrors.setText(UIText.CommitDialog_IgnoreErrors);
+
+ ignoreErrors.setSelection(false);
+ ignoreErrors.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button button = (Button) e.getSource();
+ boolean enable = button.getSelection();
+ updateMessage();
+ updateCommitButtons(enable);
+ }
+ });
+ }
+
TreeColumn statCol = new TreeColumn(resourcesTree, SWT.LEFT);
statCol.setText(UIText.CommitDialog_Status);
statCol.setWidth(150);
@@ -930,6 +958,11 @@ public class CommitDialog extends TitleAreaDialog {
return filesSection;
}
+ private void updateCommitButtons(boolean enable) {
+ commitAndPushButton.setEnabled(enable);
+ commitButton.setEnabled(enable);
+ }
+
private Composite createMessageAndPersonArea(Composite container) {
Composite messageAndPersonArea = toolkit.createComposite(container);
@@ -1123,24 +1156,46 @@ public class CommitDialog extends TitleAreaDialog {
String message = null;
int type = IMessageProvider.NONE;
- String commitMsg = commitMessageComponent.getCommitMessage();
- if (commitMsg == null || commitMsg.trim().length() == 0) {
- message = UIText.CommitDialog_Message;
- type = IMessageProvider.INFORMATION;
- } else if (!isCommitWithoutFilesAllowed()) {
- message = UIText.CommitDialog_MessageNoFilesSelected;
- type = IMessageProvider.INFORMATION;
+ boolean ignoreErrorsValue = ignoreErrors == null ? true
+ : !ignoreErrors.getSelection();
+ @SuppressWarnings("boxing")
+ boolean hasErrorsOrWarnings = getPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING)
+ ? (getProblemsSeverity() >= Integer
+ .valueOf(getPreferenceStore().getString(
+ UIPreferences.WARN_BEFORE_COMMITTING_LEVEL))
+ && ignoreErrorsValue)
+ : false;
+ if (hasErrorsOrWarnings) {
+ message = UIText.CommitDialog_MessageErrors;
+ type = IMessageProvider.WARNING;
} else {
- CommitStatus status = commitMessageComponent.getStatus();
- message = status.getMessage();
- type = status.getMessageType();
+ String commitMsg = commitMessageComponent.getCommitMessage();
+ if (commitMsg == null || commitMsg.trim().length() == 0) {
+ message = UIText.CommitDialog_Message;
+ type = IMessageProvider.INFORMATION;
+ } else if (!isCommitWithoutFilesAllowed()) {
+ message = UIText.CommitDialog_MessageNoFilesSelected;
+ type = IMessageProvider.INFORMATION;
+ } else {
+ CommitStatus status = commitMessageComponent.getStatus();
+ message = status.getMessage();
+ type = status.getMessageType();
+ }
}
-
setMessage(message, type);
- boolean commitEnabled = type == IMessageProvider.WARNING
- || type == IMessageProvider.NONE;
- commitButton.setEnabled(commitEnabled);
- commitAndPushButton.setEnabled(commitEnabled);
+ @SuppressWarnings("boxing")
+ boolean commitBlocked = getPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING)
+ && getPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT)
+ ? (getProblemsSeverity() >= Integer
+ .valueOf(getPreferenceStore().getString(
+ UIPreferences.BLOCK_COMMIT_LEVEL))
+ && ignoreErrorsValue)
+ : false;
+ boolean commitEnabled = (type == IMessageProvider.WARNING
+ || type == IMessageProvider.NONE) && !commitBlocked;
+ updateCommitButtons(commitEnabled);
}
private boolean isCommitWithoutFilesAllowed() {
@@ -1343,6 +1398,23 @@ public class CommitDialog extends TitleAreaDialog {
super.okPressed();
}
+ private int getProblemsSeverity() {
+ int result = IProblemDecoratable.SEVERITY_NONE;
+ Object[] checkedElements = filesViewer.getCheckedElements();
+ ArrayList<String> selectedFiles = new ArrayList<>();
+ for (Object obj : checkedElements)
+ selectedFiles.add(((CommitItem) obj).path);
+ for (final CommitItem item : items) {
+ if (item.getProblemSeverity() >= IMarker.SEVERITY_WARNING
+ && selectedFiles.contains(item.path)) {
+ if (result < item.getProblemSeverity()) {
+ result = item.getProblemSeverity();
+ }
+ }
+ }
+ return result;
+ }
+
@Override
protected int getShellStyle() {
return super.getShellStyle() | SWT.RESIZE;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/CommittingPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/CommittingPreferencePage.java
index 25d51b73d..f86601bcc 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/CommittingPreferencePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/CommittingPreferencePage.java
@@ -10,15 +10,21 @@
package org.eclipse.egit.ui.internal.preferences;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.PluginPreferenceInitializer;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
@@ -28,6 +34,16 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class CommittingPreferencePage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
+ private Button warnCheckbox;
+
+ private Group buildProblemsGroup;
+
+ private ComboFieldEditor warnCombo;
+
+ private Button blockCheckbox;
+
+ private ComboFieldEditor blockCombo;
+
/** */
public CommittingPreferencePage() {
super(GRID);
@@ -84,10 +100,59 @@ public class CommittingPreferencePage extends FieldEditorPreferencePage
addField(signedOffBy);
updateMargins(footersGroup);
- IntegerFieldEditor historySize = new IntegerFieldEditor(
- UIPreferences.COMMIT_DIALOG_HISTORY_SIZE,
- UIText.CommittingPreferencePage_commitMessageHistory, main);
- addField(historySize);
+ buildProblemsGroup = createGroup(main, 1);
+ buildProblemsGroup.setText(
+ UIText.CommittingPreferencePage_WarnBeforeCommittingTitle);
+ GridDataFactory.fillDefaults().grab(true, false).span(3, 1)
+ .applyTo(buildProblemsGroup);
+
+ warnCheckbox = createCheckBox(buildProblemsGroup,
+ UIText.CommittingPreferencePage_CheckBeforeCommitting);
+ ((GridData) warnCheckbox.getLayoutData()).horizontalSpan = 3;
+ warnCheckbox.setSelection(doGetPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING));
+ warnCheckbox.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ handleWarnCheckboxSelection(warnCheckbox.getSelection());
+ }
+ });
+
+ warnCombo = new ComboFieldEditor(UIPreferences.WARN_BEFORE_COMMITTING_LEVEL,
+ UIText.CommittingPreferencePage_WarnBeforeCommitting,
+ new String[][] {
+ { UIText.CommittingPreferencePage_WarnBlock_Errors,
+ PluginPreferenceInitializer.COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_ERRORS },
+ { UIText.CommittingPreferencePage_WarnBlock_WarningsAndErrors,
+ PluginPreferenceInitializer.COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_WARNINGS_AND_ERRORS } },
+ buildProblemsGroup);
+ addField(warnCombo);
+
+ blockCheckbox = createCheckBox(buildProblemsGroup,
+ UIText.CommittingPreferencePage_BlockCommit);
+ ((GridData) blockCheckbox.getLayoutData()).horizontalSpan = 3;
+ blockCheckbox.setSelection(
+ doGetPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT));
+ blockCheckbox.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ handleBlockCheckboxSelection(blockCheckbox.getSelection());
+ }
+ });
+
+ blockCombo = new ComboFieldEditor(UIPreferences.BLOCK_COMMIT_LEVEL,
+ UIText.CommittingPreferencePage_BlockCommitCombo,
+ new String[][] {
+ { UIText.CommittingPreferencePage_WarnBlock_Errors,
+ PluginPreferenceInitializer.COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_ERRORS },
+ { UIText.CommittingPreferencePage_WarnBlock_WarningsAndErrors,
+ PluginPreferenceInitializer.COMMITTING_PREFERENCE_PAGE_WARN_BLOCK_WARNINGS_AND_ERRORS } },
+ buildProblemsGroup);
+ addField(blockCombo);
+
+ handleWarnCheckboxSelection(warnCheckbox.getSelection());
+ handleBlockCheckboxSelection(blockCheckbox.getSelection());
+ updateMargins(buildProblemsGroup);
BooleanFieldEditor includeUntracked = new BooleanFieldEditor(
UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED,
@@ -95,6 +160,11 @@ public class CommittingPreferencePage extends FieldEditorPreferencePage
includeUntracked.getDescriptionControl(main).setToolTipText(
UIText.CommittingPreferencePage_includeUntrackedFilesTooltip);
addField(includeUntracked);
+
+ IntegerFieldEditor historySize = new IntegerFieldEditor(
+ UIPreferences.COMMIT_DIALOG_HISTORY_SIZE,
+ UIText.CommittingPreferencePage_commitMessageHistory, main);
+ addField(historySize);
}
private void updateMargins(Group group) {
@@ -104,4 +174,47 @@ public class CommittingPreferencePage extends FieldEditorPreferencePage
layout.marginWidth = 5;
layout.marginHeight = 5;
}
+
+ private Button createCheckBox(Composite group, String label) {
+ Button button = new Button(group, SWT.CHECK | SWT.LEFT);
+ button.setText(label);
+ GridData data = new GridData(GridData.FILL);
+ data.verticalAlignment = GridData.CENTER;
+ data.horizontalAlignment = GridData.FILL;
+ button.setLayoutData(data);
+ return button;
+ }
+
+ private void handleBlockCheckboxSelection(boolean selection) {
+ blockCombo.setEnabled(selection, buildProblemsGroup);
+ }
+
+ private void handleWarnCheckboxSelection(boolean selection) {
+ warnCombo.setEnabled(selection, buildProblemsGroup);
+ blockCheckbox.setEnabled(selection);
+ blockCombo.setEnabled(selection, buildProblemsGroup);
+ }
+
+ @Override
+ public boolean performOk() {
+ doGetPreferenceStore().setValue(UIPreferences.WARN_BEFORE_COMMITTING,
+ warnCheckbox.getSelection());
+ doGetPreferenceStore().setValue(UIPreferences.BLOCK_COMMIT,
+ blockCheckbox.getSelection());
+ return super.performOk();
+ }
+
+ private Group createGroup(Composite parent, int numColumns) {
+ Group group = new Group(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = numColumns;
+ group.setLayout(layout);
+ GridData data = new GridData(SWT.FILL);
+ data.horizontalIndent = 0;
+ data.verticalAlignment = SWT.FILL;
+ data.horizontalAlignment = SWT.END;
+ data.grabExcessHorizontalSpace = true;
+ group.setLayoutData(data);
+ return group;
+ }
}
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 bf3dc02ca..5b7b001c0 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
@@ -28,6 +28,7 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -73,6 +74,7 @@ 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.components.ToggleableWarningLabel;
+import org.eclipse.egit.ui.internal.decorators.IProblemDecoratable;
import org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator;
import org.eclipse.egit.ui.internal.dialogs.CommitMessageArea;
import org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent;
@@ -570,6 +572,8 @@ public class StagingView extends ViewPart implements IShowInSource {
private Button rebaseAbortButton;
+ private Button ignoreErrors;
+
private ListenerHandle refsChangedListener;
private LocalResourceManager resources = new LocalResourceManager(
@@ -866,6 +870,34 @@ public class StagingView extends ViewPart implements IShowInSource {
GridLayoutFactory.fillDefaults().numColumns(2)
.applyTo(buttonsContainer);
+ ignoreErrors = toolkit.createButton(buttonsContainer,
+ UIText.StagingView_IgnoreErrors, SWT.CHECK);
+ ignoreErrors.setSelection(false);
+ ignoreErrors.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateMessage();
+ updateCommitButtons();
+ }
+ });
+ getPreferenceStore()
+ .addPropertyChangeListener(new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (isDisposed()) {
+ getPreferenceStore()
+ .removePropertyChangeListener(this);
+ }
+ updateIgnoreErrorsButtonVisibility();
+ updateMessage();
+ updateCommitButtons();
+ }
+ });
+
+ GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING)
+ .grab(true, true).applyTo(ignoreErrors);
+ updateIgnoreErrorsButtonVisibility();
+
Label filler = toolkit.createLabel(buttonsContainer, ""); //$NON-NLS-1$
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
.grab(true, true).applyTo(filler);
@@ -877,6 +909,7 @@ public class StagingView extends ViewPart implements IShowInSource {
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true)
.applyTo(commitButtonsContainer);
+
this.commitAndPushButton = toolkit.createButton(commitButtonsContainer,
UIText.StagingView_CommitAndPush, SWT.PUSH);
commitAndPushButton.addSelectionListener(new SelectionAdapter() {
@@ -1080,6 +1113,53 @@ public class StagingView extends ViewPart implements IShowInSource {
service.showBusyForFamily(org.eclipse.egit.core.JobFamilies.INDEX_DIFF_CACHE_UPDATE);
}
+ private boolean commitAndPushEnabled(boolean commitEnabled) {
+ return commitEnabled
+ && !currentRepository.getRepositoryState().isRebasing();
+ }
+
+ private void updateIgnoreErrorsButtonVisibility() {
+ boolean visible = getPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING)
+ && getPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT);
+ showControl(ignoreErrors, visible);
+ ignoreErrors.getParent().layout(true);
+ }
+
+ private int getProblemsSeverity() {
+ int result = IProblemDecoratable.SEVERITY_NONE;
+ StagingViewContentProvider stagedContentProvider = getContentProvider(
+ stagedViewer);
+ StagingEntry[] entries = stagedContentProvider.getStagingEntries();
+ for (StagingEntry entry : entries) {
+ if (entry.getProblemSeverity() >= IMarker.SEVERITY_WARNING) {
+ if (result < entry.getProblemSeverity()) {
+ result = entry.getProblemSeverity();
+ }
+ }
+ }
+ return result;
+ }
+
+ private void updateCommitButtons() {
+ IndexDiffData indexDiff;
+ if (cacheEntry != null) {
+ indexDiff = cacheEntry.getIndexDiff();
+ } else {
+ indexDiff = doReload(currentRepository);
+ }
+ boolean indexDiffAvailable = indexDiffAvailable(indexDiff);
+ boolean noConflicts = noConflicts(indexDiff);
+
+ boolean commitEnabled = !isCommitBlocked() && noConflicts
+ && indexDiffAvailable;
+
+ boolean commitAndPushEnabled = commitAndPushEnabled(commitEnabled);
+
+ commitButton.setEnabled(commitEnabled);
+ commitAndPushButton.setEnabled(commitAndPushEnabled);
+ }
+
private void saveSashFormWeightsOnDisposal(final SashForm sashForm,
final String settingsKey) {
sashForm.addDisposeListener(new DisposeListener() {
@@ -1711,20 +1791,25 @@ public class StagingView extends ViewPart implements IShowInSource {
}
private void updateMessage() {
- String message = commitMessageComponent.getStatus().getMessage();
- boolean needsRedraw = false;
- if (message != null) {
- warningLabel.showMessage(message);
- needsRedraw = true;
+ if (hasErrorsOrWarnings()) {
+ warningLabel.showMessage(UIText.StagingView_MessageErrors);
+ commitMessageSection.redraw();
} else {
- needsRedraw = warningLabel.getVisible();
- warningLabel.hideMessage();
+ String message = commitMessageComponent.getStatus().getMessage();
+ boolean needsRedraw = false;
+ if (message != null) {
+ warningLabel.showMessage(message);
+ needsRedraw = true;
+ } else {
+ needsRedraw = warningLabel.getVisible();
+ warningLabel.hideMessage();
+ }
+ // Without this explicit redraw, the ControlDecoration of the
+ // commit message area would not get updated and cause visual
+ // corruption.
+ if (needsRedraw)
+ commitMessageSection.redraw();
}
- // Without this explicit redraw, the ControlDecoration of the
- // commit message area would not get updated and cause visual
- // corruption.
- if (needsRedraw)
- commitMessageSection.redraw();
}
private void compareWith(OpenEvent event) {
@@ -2475,6 +2560,7 @@ public class StagingView extends ViewPart implements IShowInSource {
} else {
form.setText(UIText.StagingView_NoSelectionTitle);
}
+ updateIgnoreErrorsButtonVisibility();
}
/**
@@ -2563,15 +2649,8 @@ public class StagingView extends ViewPart implements IShowInSource {
}
final IndexDiffData indexDiff = doReload(repository);
- boolean indexDiffAvailable;
- boolean noConflicts;
- if (indexDiff == null) {
- indexDiffAvailable = false;
- noConflicts = true;
- } else {
- indexDiffAvailable = true;
- noConflicts = indexDiff.getConflicting().isEmpty();
- }
+ boolean indexDiffAvailable = indexDiffAvailable(indexDiff);
+ boolean noConflicts = noConflicts(indexDiff);
if (repositoryChanged) {
// Reset paths, they're from the old repository
@@ -2605,15 +2684,7 @@ public class StagingView extends ViewPart implements IShowInSource {
updateRebaseButtonVisibility(repository.getRepositoryState()
.isRebasing());
-
- boolean commitEnabled = indexDiffAvailable
- && repository.getRepositoryState().canCommit()
- && noConflicts;
- commitButton.setEnabled(commitEnabled);
-
- boolean commitAndPushEnabled = commitEnabled
- && !repository.getRepositoryState().isRebasing();
- commitAndPushButton.setEnabled(commitAndPushEnabled);
+ updateIgnoreErrorsButtonVisibility();
boolean rebaseContinueEnabled = indexDiffAvailable
&& repository.getRepositoryState().isRebasing()
@@ -2623,11 +2694,42 @@ public class StagingView extends ViewPart implements IShowInSource {
form.setText(GitLabels.getStyledLabelSafe(repository).toString());
updateCommitMessageComponent(repositoryChanged, indexDiffAvailable);
enableCommitWidgets(indexDiffAvailable && noConflicts);
+
+ updateCommitButtons();
updateSectionText();
}
+
});
}
+ private static boolean noConflicts(IndexDiffData indexDiff) {
+ return indexDiff == null ? true : indexDiff.getConflicting().isEmpty();
+ }
+
+ private static boolean indexDiffAvailable(IndexDiffData indexDiff) {
+ return indexDiff == null ? false : true;
+ }
+
+ private boolean hasErrorsOrWarnings() {
+ return getPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING)
+ ? (getProblemsSeverity() >= Integer.valueOf(getPreferenceStore()
+ .getString(UIPreferences.WARN_BEFORE_COMMITTING_LEVEL))
+ && !ignoreErrors.getSelection()) : false;
+ }
+
+ @SuppressWarnings("boxing")
+ private boolean isCommitBlocked() {
+ return getPreferenceStore()
+ .getBoolean(UIPreferences.WARN_BEFORE_COMMITTING)
+ && getPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT)
+ ? (getProblemsSeverity() >= Integer
+ .valueOf(getPreferenceStore().getString(
+ UIPreferences.BLOCK_COMMIT_LEVEL))
+ && !ignoreErrors.getSelection())
+ : false;
+ }
+
private IndexDiffData doReload(final Repository repository) {
IndexDiffCacheEntry entry = org.eclipse.egit.core.Activator.getDefault()
.getIndexDiffCache().getIndexDiffCacheEntry(repository);
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 f11b4fcd9..58f413731 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
@@ -816,6 +816,8 @@ CommitDialog_OpenStagingViewLink=Open <a>Git Staging</a> view
CommitDialog_OpenStagingViewToolTip=For comparing and committing while still being able to navigate and use the editor, try the Git Staging view by clicking the link. The view will be opened with your repository and commit message.
CommitDialog_Path=Path
CommitDialog_Title=Commit Changes to Git Repository
+CommitDialog_IgnoreErrors=Ignore warnings and errors
+CommitDialog_MessageErrors=Fix warnings/errors before you commit changes or explicitly ignore them
CommitDialog_WrongTypeOfCommitMessageProvider=The extension used as CommitMessageProvider has the wrong type (it must implement org.eclipse.egit.ui.ICommitMessageProvider)
SpellcheckableMessageArea_redo=Redo
@@ -1026,6 +1028,13 @@ CommittingPreferencePage_includeUntrackedFiles=Include selected untracked files
CommittingPreferencePage_includeUntrackedFilesTooltip=Check selected untracked files by default
CommittingPreferencePage_signedOffBy=Insert Signed-off-by
CommittingPreferencePage_signedOffByTooltip=Insert "Signed-off-by:" footer by default
+CommittingPreferencePage_CheckBeforeCommitting=Show warning
+CommittingPreferencePage_WarnBeforeCommitting=Warn if there are:
+CommittingPreferencePage_WarnBeforeCommittingTitle=Build problems
+CommittingPreferencePage_WarnBlock_Errors=Errors
+CommittingPreferencePage_WarnBlock_WarningsAndErrors=Warnings and errors
+CommittingPreferencePage_BlockCommit=Block commit button
+CommittingPreferencePage_BlockCommitCombo=Block if there are:
BasicConfigurationDialog_ConfigLocationInfo=These settings will be stored in the Git configuration file in your home directory.
BasicConfigurationDialog_DialogMessage=When creating a commit, Git records name and e-mail of author and committer. Please fill in the information so that your commits are correctly attributed.
@@ -1792,8 +1801,10 @@ StagingView_MergeTool=Merge Tool
StagingView_AddJob=Adding files to index...
StagingView_RemoveJob=Removing files from index...
StagingView_ResetJob=Unstaging files...
+StagingView_MessageErrors=Fix warnings/errors before you commit changes or explicitly ignore them
StagingViewContentProvider_SubmoduleError=Unhandled exception while analyzing submodules
+StagingView_IgnoreErrors=Ignore warnings and errors
StashApplyCommand_applyFailed=Applying stashed commit ''{0}'' failed due to ''{1}''
StashApplyCommand_jobTitle=Apply changes from stashed commit ''{0}''
StashCreateCommand_includeUntrackedLabel=Include untracked files

Back to the top