Skip to content

Commit

Permalink
Merge pull request #9011 from JuPrgn/master
Browse files Browse the repository at this point in the history
Check Before script failure to abort action
  • Loading branch information
RussKie committed Mar 28, 2021
2 parents c9b8c73 + 75008b8 commit 0709c44
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 15 deletions.
9 changes: 7 additions & 2 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion GitUI/CommandsDialogs/FormCheckoutBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand Down
8 changes: 6 additions & 2 deletions GitUI/CommandsDialogs/FormCheckoutRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion GitUI/CommandsDialogs/FormCreateTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion GitUI/CommandsDialogs/FormDeleteRemoteBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion GitUI/CommandsDialogs/FormDeleteTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions GitUI/CommandsDialogs/FormMergeBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
15 changes: 11 additions & 4 deletions GitUI/CommandsDialogs/FormPull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ public DialogResult PullChanges(IWin32Window? owner)
return DialogResult.No;
}

executeBeforeScripts();
if (!executeBeforeScripts())
{
return DialogResult.No;
}

var stashed = CalculateStashedValue(owner);

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion GitUI/CommandsDialogs/FormPush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,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;
Expand Down

0 comments on commit 0709c44

Please sign in to comment.