Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormPush multiple: force-with-lease if rejected #8549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions GitUI/CommandsDialogs/FormPush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ public partial class FormPush : GitModuleForm
private readonly TranslationString _updateTrackingReference =
new TranslationString("The branch {0} does not have a tracking reference. Do you want to add a tracking reference to {1}?");

private readonly TranslationString _pullRepositoryMainInstruction = new TranslationString("Pull latest changes from remote repository");
private readonly TranslationString _pullRepository =
private readonly TranslationString _pullRepositoryMainMergeInstruction = new TranslationString("Pull latest changes from remote repository");
private readonly TranslationString _pullRepositoryMainForceInstruction = new TranslationString("Push rejected");
private readonly TranslationString _pullRepositoryMergeInstruction =
new TranslationString("The push was rejected because the tip of your current branch is behind its remote counterpart. " +
"Merge the remote changes before pushing again.");
private readonly TranslationString _pullRepositoryForceInstruction =
new TranslationString("The push was rejected because the tip of your current branch is behind its remote counterpart");
private readonly TranslationString _pullDefaultButton = new TranslationString("Pull with the default pull action ({0})");
private readonly TranslationString _pullRebaseButton = new TranslationString("Pull with rebase");
private readonly TranslationString _pullMergeButton = new TranslationString("Pull with merge");
Expand Down Expand Up @@ -516,12 +519,14 @@ private bool HandlePushOnExit(ref bool isError, FormProcess form)
return false;
}

// auto pull only if current branch was rejected
var isRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranchName) + ".*", RegexOptions.Compiled);
if (isRejected.IsMatch(form.GetOutputString()) && !Module.IsBareRepository())
// if push was rejected, offer force push and for current branch also pull/merge
// Note that the Git output contains color codes etc too
var isRejected = new Regex($"! \\[rejected\\] .* ((?<currBranch>{Regex.Escape(_currentBranchName)})|.*) -> ");
Match match = isRejected.Match(form.GetOutputString());
if (match.Success && !Module.IsBareRepository())
{
IWin32Window owner = form.Owner;
(var onRejectedPullAction, var forcePush) = AskForAutoPullOnPushRejectedAction(owner);
(var onRejectedPullAction, var forcePush) = AskForAutoPullOnPushRejectedAction(owner, match.Groups["currBranch"].Success);

if (forcePush)
{
Expand Down Expand Up @@ -581,7 +586,7 @@ private bool HandlePushOnExit(ref bool isError, FormProcess form)
return false;
}

private (AppSettings.PullAction pullAction, bool forcePush) AskForAutoPullOnPushRejectedAction(IWin32Window owner)
private (AppSettings.PullAction pullAction, bool forcePush) AskForAutoPullOnPushRejectedAction(IWin32Window owner, bool allOptions)
{
bool forcePush = false;
AppSettings.PullAction? onRejectedPullAction = AppSettings.AutoPullOnPushRejectedAction;
Expand Down Expand Up @@ -612,8 +617,8 @@ private bool HandlePushOnExit(ref bool isError, FormProcess form)
using var dialog = new TaskDialog
{
OwnerWindowHandle = owner.Handle,
Text = _pullRepository.Text,
InstructionText = _pullRepositoryMainInstruction.Text,
Text = allOptions ? _pullRepositoryMergeInstruction.Text : _pullRepositoryForceInstruction.Text,
InstructionText = allOptions ? _pullRepositoryMainMergeInstruction.Text : _pullRepositoryMainForceInstruction.Text,
Caption = string.Format(_pullRepositoryCaption.Text, destination),
StandardButtons = TaskDialogStandardButtons.Cancel,
Icon = TaskDialogStandardIcon.Error,
Expand Down Expand Up @@ -646,9 +651,13 @@ private bool HandlePushOnExit(ref bool isError, FormProcess form)
dialogResult = 3;
dialog.Close();
};
dialog.Controls.Add(btnPullDefault);
dialog.Controls.Add(btnPullRebase);
dialog.Controls.Add(btnPullMerge);
if (allOptions)
{
dialog.Controls.Add(btnPullDefault);
dialog.Controls.Add(btnPullRebase);
dialog.Controls.Add(btnPullMerge);
}

dialog.Controls.Add(btnPushForce);

dialog.Show();
Expand Down
18 changes: 13 additions & 5 deletions GitUI/Translation/English.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -5401,18 +5401,26 @@ Would you like to do it now?</source>
<source>Pull with rebase</source>
<target />
</trans-unit>
<trans-unit id="_pullRepository.Text">
<source>The push was rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes before pushing again.</source>
<target />
</trans-unit>
<trans-unit id="_pullRepositoryCaption.Text">
<source>Push was rejected from "{0}"</source>
<target />
</trans-unit>
<trans-unit id="_pullRepositoryMainInstruction.Text">
<trans-unit id="_pullRepositoryForceInstruction.Text">
<source>The push was rejected because the tip of your current branch is behind its remote counterpart</source>
<target />
</trans-unit>
<trans-unit id="_pullRepositoryMainForceInstruction.Text">
<source>Push rejected</source>
<target />
</trans-unit>
<trans-unit id="_pullRepositoryMainMergeInstruction.Text">
<source>Pull latest changes from remote repository</source>
<target />
</trans-unit>
<trans-unit id="_pullRepositoryMergeInstruction.Text">
<source>The push was rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes before pushing again.</source>
<target />
</trans-unit>
<trans-unit id="_pushCaption.Text">
<source>Push</source>
<target />
Expand Down