Skip to content

Commit

Permalink
Add scripts for BeforeFetch and AfterFetch (#7026)
Browse files Browse the repository at this point in the history
Additional scripts that should be executed before/after fetch can be added.

Fixes #4909
  • Loading branch information
KarstenRa authored and RussKie committed Aug 23, 2019
1 parent 2406eb8 commit 1554b21
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
9 changes: 8 additions & 1 deletion GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,14 @@ private void FindFileInSelectedCommit()

private void QuickFetch()
{
FormProcess.ShowDialog(this, Module.FetchCmd(string.Empty, string.Empty, string.Empty));
ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch);
var success = FormProcess.ShowDialog(this, Module.FetchCmd(string.Empty, string.Empty, string.Empty));
if (!success)
{
return;
}

ScriptManager.RunEventScripts(this, ScriptEvent.AfterFetch);
UICommands.RepoChangedNotifier.Notify();
}

Expand Down
42 changes: 36 additions & 6 deletions GitUI/CommandsDialogs/FormPull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public DialogResult PullChanges(IWin32Window owner)
return DialogResult.No;
}

ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull);
executeBeforeScripts();

var stashed = CalculateStashedValue(owner);

Expand All @@ -412,9 +412,12 @@ public DialogResult PullChanges(IWin32Window owner)
form.ShowDialog(owner);
ErrorOccurred = form.ErrorOccurred();

bool executeScripts = false;
try
{
bool aborted = form.DialogResult == DialogResult.Abort;
executeScripts = !aborted && !ErrorOccurred;

if (!aborted && !Fetch.Checked)
{
if (!ErrorOccurred)
Expand All @@ -426,7 +429,7 @@ public DialogResult PullChanges(IWin32Window owner)
}
else
{
CheckMergeConflictsOnError();
executeScripts |= CheckMergeConflictsOnError();
}
}
}
Expand All @@ -437,7 +440,10 @@ public DialogResult PullChanges(IWin32Window owner)
PopStash();
}

ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull);
if (executeScripts)
{
executeAfterScripts();
}
}
}

Expand Down Expand Up @@ -511,17 +517,19 @@ bool AskIfSubmodulesShouldBeInitialized()
}
}

void CheckMergeConflictsOnError()
bool CheckMergeConflictsOnError()
{
// Rebase failed -> special 'rebase' merge conflict
if (Rebase.Checked && Module.InTheMiddleOfRebase())
{
UICommands.StartTheContinueRebaseDialog(owner);
return UICommands.StartTheContinueRebaseDialog(owner);
}
else if (Module.InTheMiddleOfAction())
{
MergeConflictHandler.HandleMergeConflicts(UICommands, owner);
return MergeConflictHandler.HandleMergeConflicts(UICommands, owner);
}

return false;
}

void PopStash()
Expand Down Expand Up @@ -557,6 +565,28 @@ void PopStash()
UICommands.StashPop(owner);
}
}

void executeBeforeScripts()
{
// Request to pull/merge in addition to the fetch
if (!Fetch.Checked)
{
ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull);
}

ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch);
}

void executeAfterScripts()
{
ScriptManager.RunEventScripts(this, ScriptEvent.AfterFetch);

// Request to pull/merge in addition to the fetch
if (!Fetch.Checked)
{
ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull);
}
}
}

private void UpdateSettingsDuringPull()
Expand Down
4 changes: 3 additions & 1 deletion GitUI/Script/ScriptInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public enum ScriptEvent
BeforeCheckout,
AfterCheckout,
BeforeMerge,
AfterMerge
AfterMerge,
BeforeFetch,
AfterFetch
}

public class ScriptInfo
Expand Down

0 comments on commit 1554b21

Please sign in to comment.