diff --git a/GitUI/CommandsDialogs/FormCommit.cs b/GitUI/CommandsDialogs/FormCommit.cs index c03c062a1a8..279e8bd94fb 100644 --- a/GitUI/CommandsDialogs/FormCommit.cs +++ b/GitUI/CommandsDialogs/FormCommit.cs @@ -200,6 +200,12 @@ private CommitKind CommitKind } } + /// + /// Flag whether the push must be forced, i.e. after amending a commit or after soft reset to the previous commit. + /// + /// 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() @@ -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()) @@ -1207,7 +1217,7 @@ private void CheckForStagedAndCommit(bool amend, bool push, bool resetAuthor) bool ConfirmOrStageCommit() { - if (amend) + if (createAmendCommit) { return ConfirmAmendCommit(); } @@ -1374,7 +1384,7 @@ void DoCommit() } var commitCmd = Module.CommitCmd( - amend, + createAmendCommit, signOffToolStripMenuItem.Checked, toolAuthor.Text, _useFormCommitMessage, @@ -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 @@ -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() @@ -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) @@ -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(); @@ -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; }