Skip to content

Commit

Permalink
fixup! FormCommit: Add soft reset for amending
Browse files Browse the repository at this point in the history
Really force push when doing in single steps:
- soft reset
- commit
- push
  • Loading branch information
mstv committed Feb 27, 2023
1 parent 03357ca commit 53e1a48
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ private CommitKind CommitKind
}
}

/// <summary>
/// Flag whether the push must be forced, i.e. after amending a commit or after soft reset to the previous commit.
/// </summary>
/// The Amend checkbox is disabled after soft reset.
private bool PushForced => (Amend.Checked || !Amend.Enabled) && AppSettings.CommitAndPushForcedWhenAmend;

[Obsolete("For VS designer and translation test only. Do not remove.")]
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private FormCommit()
Expand Down Expand Up @@ -1195,8 +1201,12 @@ private void CommitClick(object sender, EventArgs e)
ExecuteCommitCommand();
}

private void CheckForStagedAndCommit(bool amend, bool push, bool resetAuthor)
private void CheckForStagedAndCommit(bool push)
{
bool createAmendCommit = Amend.Checked;
bool resetAuthor = Amend.Checked && ResetAuthor.Checked;
bool pushForced = PushForced;

BypassFormActivatedEventHandler(() =>
{
if (ConfirmOrStageCommit())
Expand All @@ -1207,7 +1217,7 @@ private void CheckForStagedAndCommit(bool amend, bool push, bool resetAuthor)

bool ConfirmOrStageCommit()
{
if (amend)
if (createAmendCommit)
{
return ConfirmAmendCommit();
}
Expand Down Expand Up @@ -1374,7 +1384,7 @@ void DoCommit()
}

var commitCmd = Module.CommitCmd(
amend,
createAmendCommit,
signOffToolStripMenuItem.Checked,
toolAuthor.Text,
_useFormCommitMessage,
Expand Down Expand Up @@ -1403,8 +1413,7 @@ void DoCommit()
{
if (push)
{
bool pushForced = AppSettings.CommitAndPushForcedWhenAmend && amend;
UICommands.StartPushDialog(this, true, pushForced, out pushCompleted);
UICommands.StartPushDialog(owner: this, pushOnShow: true, forceWithLease: pushForced, out pushCompleted);
}
}
finally
Expand Down Expand Up @@ -2801,11 +2810,12 @@ private void CommitAndPush_Click(object sender, EventArgs e)
{
if (CommitAndPush.Text == TranslatedStrings.ButtonPush)
{
UICommands.StartPushDialog(this, pushOnShow: true);
bool pushForced = CommitAndPush.BackColor == OtherColors.AmendButtonForcedColor;
UICommands.StartPushDialog(owner: this, pushOnShow: true, forceWithLease: pushForced, out _);
return;
}

CheckForStagedAndCommit(amend: Amend.Checked, push: true, resetAuthor: Amend.Checked && ResetAuthor.Checked);
CheckForStagedAndCommit(push: true);
}

private void UpdateAuthorInfo()
Expand Down Expand Up @@ -2856,7 +2866,7 @@ private void ViewFileHistoryMenuItem_Click(object sender, EventArgs e)

private void ExecuteCommitCommand()
{
CheckForStagedAndCommit(amend: Amend.Checked, push: false, resetAuthor: Amend.Checked && ResetAuthor.Checked);
CheckForStagedAndCommit(push: false);
}

private void Message_KeyDown(object sender, KeyEventArgs e)
Expand Down Expand Up @@ -3326,7 +3336,7 @@ private void Amend_CheckedChanged(object sender, EventArgs e)

if (AppSettings.CommitAndPushForcedWhenAmend)
{
CommitAndPush.BackColor = Amend.Checked || !Amend.Enabled
CommitAndPush.BackColor = PushForced
? OtherColors.AmendButtonForcedColor
: SystemColors.ButtonFace.AdaptBackColor();

Expand Down Expand Up @@ -3409,9 +3419,8 @@ private void stopTrackingThisFileToolStripMenuItem_Click(object sender, EventArg

private void SetCommitAndPushText()
{
bool amending = Amend.Checked || !Amend.Enabled;
CommitAndPush.Text = amending && AppSettings.CommitAndPushForcedWhenAmend ? _commitAndForcePush.Text
: Reset.Enabled || amending ? _commitAndPush.Text
CommitAndPush.Text = PushForced ? _commitAndForcePush.Text
: Reset.Enabled || Amend.Checked ? _commitAndPush.Text
: TranslatedStrings.ButtonPush;
}

Expand Down

0 comments on commit 53e1a48

Please sign in to comment.