From 75008b83004e038009ee1b90acbea66fd2dcfe82 Mon Sep 17 00:00:00 2001 From: Julien PEYREGNE Date: Thu, 18 Mar 2021 14:05:13 +0100 Subject: [PATCH] Check Before script failure to abort action --- GitUI/CommandsDialogs/FormBrowse.cs | 9 +++++++-- GitUI/CommandsDialogs/FormCheckoutBranch.cs | 6 +++++- GitUI/CommandsDialogs/FormCheckoutRevision.cs | 8 ++++++-- GitUI/CommandsDialogs/FormCreateTag.cs | 6 +++++- GitUI/CommandsDialogs/FormDeleteRemoteBranch.cs | 6 +++++- GitUI/CommandsDialogs/FormDeleteTag.cs | 6 +++++- GitUI/CommandsDialogs/FormMergeBranch.cs | 9 +++++++-- GitUI/CommandsDialogs/FormPull.cs | 15 +++++++++++---- GitUI/CommandsDialogs/FormPush.cs | 6 +++++- 9 files changed, 56 insertions(+), 15 deletions(-) diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 1c7d8b6d0e1..3885e1b56e5 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -2300,8 +2300,13 @@ private void FindFileInSelectedCommit() private void QuickFetch() { - ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch); - bool success = FormProcess.ShowDialog(this, process: null, arguments: Module.FetchCmd(string.Empty, string.Empty, string.Empty), Module.WorkingDir, input: null, useDialogSettings: true); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch); + if (!success) + { + return; + } + + success = FormProcess.ShowDialog(this, process: null, arguments: Module.FetchCmd(string.Empty, string.Empty, string.Empty), Module.WorkingDir, input: null, useDialogSettings: true); if (!success) { return; diff --git a/GitUI/CommandsDialogs/FormCheckoutBranch.cs b/GitUI/CommandsDialogs/FormCheckoutBranch.cs index 30a81a056f2..00f9b03833d 100644 --- a/GitUI/CommandsDialogs/FormCheckoutBranch.cs +++ b/GitUI/CommandsDialogs/FormCheckoutBranch.cs @@ -372,7 +372,11 @@ private DialogResult PerformCheckout(IWin32Window? owner) Debug.Assert(originalId is not null, "originalId is not null"); - ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); + if (!success) + { + return DialogResult.Cancel; + } if (UICommands.StartCommandLineProcessDialog(owner, new GitCheckoutBranchCmd(branchName, isRemote, localChanges, newBranchMode, newBranchName))) { diff --git a/GitUI/CommandsDialogs/FormCheckoutRevision.cs b/GitUI/CommandsDialogs/FormCheckoutRevision.cs index fb78f5d0a90..f87f16d9b73 100644 --- a/GitUI/CommandsDialogs/FormCheckoutRevision.cs +++ b/GitUI/CommandsDialogs/FormCheckoutRevision.cs @@ -48,10 +48,14 @@ private void OkClick(object sender, EventArgs e) Debug.Assert(checkedOutObjectId is not null, "checkedOutObjectId is not null"); - ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); + if (!success) + { + return; + } string command = GitCommandHelpers.CheckoutCmd(selectedObjectId.ToString(), Force.Checked ? LocalChangesAction.Reset : 0); - bool success = FormProcess.ShowDialog(this, process: null, arguments: command, Module.WorkingDir, input: null, useDialogSettings: true); + success = FormProcess.ShowDialog(this, process: null, arguments: command, Module.WorkingDir, input: null, useDialogSettings: true); if (success) { if (selectedObjectId != checkedOutObjectId) diff --git a/GitUI/CommandsDialogs/FormCreateTag.cs b/GitUI/CommandsDialogs/FormCreateTag.cs index 62c42246be9..25abdec78f7 100644 --- a/GitUI/CommandsDialogs/FormCreateTag.cs +++ b/GitUI/CommandsDialogs/FormCreateTag.cs @@ -116,7 +116,11 @@ private void PushTag(string tagName) { var pushCmd = GitCommandHelpers.PushTagCmd(_currentRemote, tagName, false); - ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + if (!success) + { + return; + } using var form = new FormRemoteProcess(UICommands, process: null, pushCmd) { diff --git a/GitUI/CommandsDialogs/FormDeleteRemoteBranch.cs b/GitUI/CommandsDialogs/FormDeleteRemoteBranch.cs index f3cf4e4fe50..ad4f1bc0e41 100644 --- a/GitUI/CommandsDialogs/FormDeleteRemoteBranch.cs +++ b/GitUI/CommandsDialogs/FormDeleteRemoteBranch.cs @@ -79,7 +79,11 @@ private void OkClick(object sender, EventArgs e) var cmd = new GitDeleteRemoteBranchesCmd(remote, branches.Select(x => x.LocalName)); - ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + if (!success) + { + return; + } using var form = new FormRemoteProcess(UICommands, process: null, cmd.Arguments) { diff --git a/GitUI/CommandsDialogs/FormDeleteTag.cs b/GitUI/CommandsDialogs/FormDeleteTag.cs index 579d7acb3a2..8036447d9ac 100644 --- a/GitUI/CommandsDialogs/FormDeleteTag.cs +++ b/GitUI/CommandsDialogs/FormDeleteTag.cs @@ -63,7 +63,11 @@ private void RemoveRemoteTag(string tagName) { var pushCmd = string.Format("push \"{0}\" :refs/tags/{1}", remotesComboboxControl1.SelectedRemote, tagName); - ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + if (!success) + { + return; + } using var form = new FormRemoteProcess(UICommands, process: null, pushCmd); ////Remote = currentRemote, diff --git a/GitUI/CommandsDialogs/FormMergeBranch.cs b/GitUI/CommandsDialogs/FormMergeBranch.cs index 5bcb8f9de92..51d731fbe2d 100644 --- a/GitUI/CommandsDialogs/FormMergeBranch.cs +++ b/GitUI/CommandsDialogs/FormMergeBranch.cs @@ -88,7 +88,12 @@ private void OkClick(object sender, EventArgs e) { Module.EffectiveSettings.NoFastForwardMerge = noFastForward.Checked; AppSettings.DontCommitMerge = noCommit.Checked; - ScriptManager.RunEventScripts(this, ScriptEvent.BeforeMerge); + + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforeMerge); + if (!success) + { + return; + } string? mergeMessagePath = null; if (addMergeMessage.Checked) @@ -109,7 +114,7 @@ private void OkClick(object sender, EventArgs e) allowUnrelatedHistories.Checked, mergeMessagePath, addLogMessages.Checked ? (int)nbMessages.Value : (int?)null); - bool success = FormProcess.ShowDialog(this, process: null, arguments: command, Module.WorkingDir, input: null, useDialogSettings: true); + success = FormProcess.ShowDialog(this, process: null, arguments: command, Module.WorkingDir, input: null, useDialogSettings: true); var wasConflict = MergeConflictHandler.HandleMergeConflicts(UICommands, this, !noCommit.Checked); diff --git a/GitUI/CommandsDialogs/FormPull.cs b/GitUI/CommandsDialogs/FormPull.cs index d668fb9cbd2..b9579c004e5 100644 --- a/GitUI/CommandsDialogs/FormPull.cs +++ b/GitUI/CommandsDialogs/FormPull.cs @@ -428,7 +428,10 @@ public DialogResult PullChanges(IWin32Window? owner) return DialogResult.No; } - executeBeforeScripts(); + if (!executeBeforeScripts()) + { + return DialogResult.No; + } var stashed = CalculateStashedValue(owner); @@ -596,15 +599,19 @@ void PopStash() } } - void executeBeforeScripts() + bool executeBeforeScripts() { // Request to pull/merge in addition to the fetch if (!Fetch.Checked) { - ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull); + if (!success) + { + return false; + } } - ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch); + return ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch); } void executeAfterScripts() diff --git a/GitUI/CommandsDialogs/FormPush.cs b/GitUI/CommandsDialogs/FormPush.cs index 7b8869acc8b..41b86e4eef8 100644 --- a/GitUI/CommandsDialogs/FormPush.cs +++ b/GitUI/CommandsDialogs/FormPush.cs @@ -461,7 +461,11 @@ private bool PushChanges(IWin32Window? owner) pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions); } - ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + bool success = ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); + if (!success) + { + return false; + } // controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text;