Skip to content

Commit

Permalink
FormCommit: Add soft reset for amending
Browse files Browse the repository at this point in the history
  • Loading branch information
mstv committed Feb 27, 2023
1 parent 04dafda commit 03357ca
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 80 deletions.
45 changes: 39 additions & 6 deletions GitUI/CommandsDialogs/FormCommit.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 57 additions & 13 deletions GitUI/CommandsDialogs/FormCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ public sealed partial class FormCommit : GitModuleForm
{
#region Translation

private readonly TranslationString _amendCommit =
new("You are about to rewrite history." + Environment.NewLine +
"Only use amend if the commit is not published yet!" + Environment.NewLine +
Environment.NewLine + "Do you want to continue?");
private readonly TranslationString _amendCommit
= new("You are about to rewrite history." + Environment.NewLine
+ "Only use Amend if the commit has not been published yet!" + Environment.NewLine
+ Environment.NewLine
+ "Do you want to continue?");

private readonly TranslationString _amendResetSoft
= new("You are about to rewrite history by Soft Reset to the previous commit." + Environment.NewLine
+ "Only use Amend / Reset if the commit has not been published yet!" + Environment.NewLine
+ Environment.NewLine
+ "Do you want to continue?");

private readonly TranslationString _amendCommitCaption = new("Amend commit");

Expand Down Expand Up @@ -318,6 +325,12 @@ public FormCommit(GitUICommands commands, CommitKind commitKind = CommitKind.Nor
SolveMergeconflicts.BackColor = OtherColors.MergeConflictsColor;
SolveMergeconflicts.SetForeColorForBackColor();

if (AppSettings.DontConfirmAmend)
{
ResetSoft.BackColor = OtherColors.AmendButtonForcedColor;
ResetSoft.SetForeColorForBackColor();
}

toolStripStatusBranchIcon.AdaptImageLightness();

splitLeft.Panel1.BackColor = OtherColors.PanelBorderColor;
Expand Down Expand Up @@ -763,7 +776,7 @@ private bool ResetSelectedFiles()
return false;
}

ResetSoftClick(this, EventArgs.Empty);
ResetFilesClick(this, EventArgs.Empty);
return true;
}

Expand Down Expand Up @@ -992,7 +1005,6 @@ private void Initialize(bool loadUnstaged = true)

Commit.Enabled = false;
CommitAndPush.Enabled = false;
Amend.Enabled = false;
Reset.Enabled = false;
ResetUnStaged.Enabled = false;
EnableStageButtons(false);
Expand Down Expand Up @@ -1059,7 +1071,6 @@ private void LoadUnstagedOutput(IReadOnlyList<GitItemStatus> allChangedFiles)
LoadingStaged.Visible = false;
Commit.Enabled = true;
CommitAndPush.Enabled = true;
Amend.Enabled = true;
Reset.Enabled = doChangesExist;
SetCommitAndPushText();

Expand Down Expand Up @@ -1399,6 +1410,7 @@ void DoCommit()
finally
{
Message.Text = string.Empty;
Amend.Enabled = true;
Amend.Checked = false;
noVerifyToolStripMenuItem.Checked = false;
}
Expand Down Expand Up @@ -2068,7 +2080,6 @@ private void Stage(IReadOnlyList<GitItemStatus> items)
EnableStageButtons(true);

Commit.Enabled = true;
Amend.Enabled = true;
}

if (AppSettings.RevisionGraphShowArtificialCommits)
Expand All @@ -2077,7 +2088,7 @@ private void Stage(IReadOnlyList<GitItemStatus> items)
}
}

private void ResetSoftClick(object sender, EventArgs e)
private void ResetFilesClick(object sender, EventArgs e)
{
_shouldRescanChanges = false;
try
Expand Down Expand Up @@ -2171,6 +2182,31 @@ private void ResetSoftClick(object sender, EventArgs e)
Initialize();
}

private void ResetSoftClick(object sender, EventArgs e)
{
if (!AppSettings.DontConfirmAmend)
{
if (MessageBox.Show(this, _amendResetSoft.Text, _amendCommitCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
{
return;
}
}

try
{
ArgumentString cmd = GitCommandHelpers.ResetCmd(ResetMode.Soft, "HEAD~1");
Module.GitExecutable.RunCommand(cmd);
Amend.Enabled = false;
Amend.Checked = false;
Message.Focus();
}
finally
{
UICommands.RepoChangedNotifier.Notify();
Initialize();
}
}

private void DeleteFileToolStripMenuItemClick(object sender, EventArgs e)
{
try
Expand Down Expand Up @@ -3276,7 +3312,7 @@ private void interactiveAddToolStripMenuItem_Click(object sender, EventArgs e)

private void Amend_CheckedChanged(object sender, EventArgs e)
{
ResetAuthor.Visible = Amend.Checked;
AmendPanel.Visible = Amend.Checked;

if (!Amend.Checked && ResetAuthor.Checked)
{
Expand All @@ -3290,14 +3326,16 @@ private void Amend_CheckedChanged(object sender, EventArgs e)

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

CommitAndPush.SetForeColorForBackColor();
}

SetCommitAndPushText();

ViewFirstStagedFile();
}

private void StageInSuperproject_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -3330,6 +3368,11 @@ private void createBranchToolStripButton_Click(object sender, EventArgs e)
}

private void Message_Enter(object sender, EventArgs e)
{
ViewFirstStagedFile();
}

private void ViewFirstStagedFile()
{
if (Staged.AllItemsCount != 0 && !Staged.SelectedItems.Any())
{
Expand Down Expand Up @@ -3366,8 +3409,9 @@ private void stopTrackingThisFileToolStripMenuItem_Click(object sender, EventArg

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

Expand Down
60 changes: 0 additions & 60 deletions GitUI/CommandsDialogs/FormCommit.resx
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
13 changes: 12 additions & 1 deletion GitUI/Translation/English.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,10 @@ gitex.cmd / gitex (located in the same folder as GitExtensions.exe):</source>
<source>R&amp;eset author</source>
<target />
</trans-unit>
<trans-unit id="ResetSoft.Text">
<source>Reset so&amp;ft</source>
<target />
</trans-unit>
<trans-unit id="ResetUnStaged.Text">
<source>Reset u&amp;nstaged changes</source>
<target />
Expand Down Expand Up @@ -3453,7 +3457,7 @@ gitex.cmd / gitex (located in the same folder as GitExtensions.exe):</source>
</trans-unit>
<trans-unit id="_amendCommit.Text">
<source>You are about to rewrite history.
Only use amend if the commit is not published yet!
Only use Amend if the commit has not been published yet!

Do you want to continue?</source>
<target />
Expand All @@ -3462,6 +3466,13 @@ Do you want to continue?</source>
<source>Amend commit</source>
<target />
</trans-unit>
<trans-unit id="_amendResetSoft.Text">
<source>You are about to rewrite history by Soft Reset to the previous commit.
Only use Amend / Reset if the commit has not been published yet!

Do you want to continue?</source>
<target />
</trans-unit>
<trans-unit id="_assumeUnchangedToolTip.Text">
<source>Tell git to not check the status of this file for performance benefits.
Use this feature when a file is big and never change.
Expand Down

0 comments on commit 03357ca

Please sign in to comment.