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

Add "Ignore Date" and "Committer Date Is Author Date" options to rebase dialog #8289

Merged
merged 1 commit into from
Jul 17, 2020
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
41 changes: 30 additions & 11 deletions GitCommands/Git/GitCommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,24 +427,43 @@ public static ArgumentString StopBisectCmd()
return new GitArgumentBuilder("bisect") { "reset" };
}

public static ArgumentString RebaseCmd(string branch, bool interactive, bool preserveMerges, bool autosquash, bool autoStash, string from = null, string onto = null)
public static ArgumentString RebaseCmd(
string branch, bool interactive, bool preserveMerges, bool autosquash, bool autoStash, bool ignoreDate, bool committerDateIsAuthorDate, string from = null, string onto = null)
{
if (from == null ^ onto == null)
{
throw new ArgumentException($"For arguments \"{nameof(from)}\" and \"{nameof(onto)}\", either both must have values, or neither may.");
}

return new GitArgumentBuilder("rebase")
var builder = new GitArgumentBuilder("rebase");
if (ignoreDate)
{
{ interactive, "-i" },
{ interactive && autosquash, "--autosquash" },
{ interactive && !autosquash, "--no-autosquash" },
{ preserveMerges, GitVersion.Current.SupportRebaseMerges ? "--rebase-merges" : "--preserve-merges" },
{ autoStash, "--autostash" },
from.QuoteNE(),
branch.Quote(),
{ onto != null, $"--onto {onto}" }
};
builder.Add("--ignore-date");
}
else if (committerDateIsAuthorDate)
{
builder.Add("--committer-date-is-author-date");
}
else
{
if (interactive)
{
builder.Add("-i");
builder.Add(autosquash ? "--autosquash" : "--no-autosquash");
}

if (preserveMerges)
{
builder.Add(GitVersion.Current.SupportRebaseMerges ? "--rebase-merges" : "--preserve-merges");
}
}

builder.Add(autoStash, "--autostash");
builder.Add(from.QuoteNE());
builder.Add(branch.Quote());
builder.Add(onto != null, $"--onto {onto}");

return builder;
}

public static ArgumentString AbortRebaseCmd()
Expand Down
154 changes: 94 additions & 60 deletions GitUI/CommandsDialogs/FormRebase.Designer.cs

Large diffs are not rendered by default.

46 changes: 42 additions & 4 deletions GitUI/CommandsDialogs/FormRebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,30 @@ private void MergetoolClick(object sender, EventArgs e)
EnableButtons();
}

private void InteractiveRebaseClick(object sender, EventArgs e)
private void chkInteractive_CheckedChanged(object sender, EventArgs e)
{
chkAutosquash.Enabled = chkInteractive.Checked;
}

private void chkIgnoreDate_CheckedChanged(object sender, EventArgs e)
{
ToggleDateCheckboxMutualExclusions();
}

private void chkCommitterDateIsAuthorDate_CheckedChanged(object sender, EventArgs e)
{
ToggleDateCheckboxMutualExclusions();
}

private void ToggleDateCheckboxMutualExclusions()
{
chkCommitterDateIsAuthorDate.Enabled = !chkIgnoreDate.Checked;
chkIgnoreDate.Enabled = !chkCommitterDateIsAuthorDate.Checked;
chkInteractive.Enabled = !chkIgnoreDate.Checked && !chkCommitterDateIsAuthorDate.Checked;
chkPreserveMerges.Enabled = !chkIgnoreDate.Checked && !chkCommitterDateIsAuthorDate.Checked;
chkAutosquash.Enabled = chkInteractive.Checked && !chkIgnoreDate.Checked && !chkCommitterDateIsAuthorDate.Checked;
}
RussKie marked this conversation as resolved.
Show resolved Hide resolved

private void AddFilesClick(object sender, EventArgs e)
{
UICommands.StartAddFilesDialog(this);
Expand Down Expand Up @@ -259,13 +278,13 @@ private void OkClick(object sender, EventArgs e)
{
rebaseCmd = GitCommandHelpers.RebaseCmd(
cboTo.Text, chkInteractive.Checked, chkPreserveMerges.Checked,
chkAutosquash.Checked, chkStash.Checked, txtFrom.Text, Branches.Text);
chkAutosquash.Checked, chkStash.Checked, chkIgnoreDate.Checked, chkCommitterDateIsAuthorDate.Checked, txtFrom.Text, Branches.Text);
}
else
{
rebaseCmd = GitCommandHelpers.RebaseCmd(
Branches.Text, chkInteractive.Checked,
chkPreserveMerges.Checked, chkAutosquash.Checked, chkStash.Checked);
chkPreserveMerges.Checked, chkAutosquash.Checked, chkStash.Checked, chkIgnoreDate.Checked, chkCommitterDateIsAuthorDate.Checked);
}

var dialogResult = FormProcess.ReadDialog(this, rebaseCmd);
Expand Down Expand Up @@ -314,10 +333,29 @@ private void btnChooseFromRevision_Click(object sender, EventArgs e)
}
}

private void CommitButtonClick(object sender, EventArgs e)
private void Commit_Click(object sender, EventArgs e)
{
UICommands.StartCommitDialog(this);
EnableButtons();
}

internal TestAccessor GetTestAccessor() => new TestAccessor(this);

internal readonly struct TestAccessor
{
private readonly FormRebase _form;

public TestAccessor(FormRebase form)
{
_form = form;
}

public CheckBox chkInteractive => _form.chkInteractive;
public CheckBox chkPreserveMerges => _form.chkPreserveMerges;
public CheckBox chkAutosquash => _form.chkAutosquash;
public CheckBox chkStash => _form.chkStash;
public CheckBox chkIgnoreDate => _form.chkIgnoreDate;
public CheckBox chkCommitterDateIsAuthorDate => _form.chkCommitterDateIsAuthorDate;
}
}
}
3 changes: 3 additions & 0 deletions GitUI/CommandsDialogs/FormRebase.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
8 changes: 8 additions & 0 deletions GitUI/Translation/English.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -5647,6 +5647,14 @@ Nothing to rebase.</source>
<source>Autosquash</source>
<target />
</trans-unit>
<trans-unit id="chkCommitterDateIsAuthorDate.Text">
<source>Committer date is author date</source>
<target />
</trans-unit>
<trans-unit id="chkIgnoreDate.Text">
<source>Ignore date</source>
<target />
</trans-unit>
<trans-unit id="chkInteractive.Text">
<source>Interactive Rebase</source>
<target />
Expand Down
4 changes: 2 additions & 2 deletions GitUI/UserControls/RevisionGrid/RevisionGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2592,8 +2592,8 @@ private void LaunchRebase(string command)
}

string rebaseCmd = GitCommandHelpers.RebaseCmd(
LatestSelectedRevision.FirstParentId?.ToString(),
interactive: true, preserveMerges: false, autosquash: false, autoStash: true);
LatestSelectedRevision.FirstParentId?.ToString(), interactive: true, preserveMerges: false,
autosquash: false, autoStash: true, ignoreDate: false, committerDateIsAuthorDate: false);

using (var formProcess = new FormProcess(null, rebaseCmd, Module.WorkingDir, null, true))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using CommonTestUtils;
using FluentAssertions;
using GitUI;
using GitUI.CommandsDialogs;
using NUnit.Framework;

namespace GitExtensions.UITests.CommandsDialogs
{
[Apartment(ApartmentState.STA)]
public class FormRebaseTests
{
private ReferenceRepository _referenceRepository;
private GitUICommands _commands;

[SetUp]
public void SetUp()
{
if (_referenceRepository == null)
{
_referenceRepository = new ReferenceRepository();
}
else
{
_referenceRepository.Reset();
}

_commands = new GitUICommands(_referenceRepository.Module);
}

[Test]
public void Interactive_check_enables_autosquash()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();

accessor.chkInteractive.Checked = true;

accessor.chkAutosquash.Enabled.Should().BeTrue();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Interactive_uncheck_disables_autosquash()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();
accessor.chkInteractive.Checked = true;

accessor.chkInteractive.Checked = false;

accessor.chkAutosquash.Enabled.Should().BeFalse();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Ignore_date_check_disables_all_other_options()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();

accessor.chkIgnoreDate.Checked = true;

accessor.chkInteractive.Enabled.Should().BeFalse();
accessor.chkPreserveMerges.Enabled.Should().BeFalse();
accessor.chkAutosquash.Enabled.Should().BeFalse();
accessor.chkCommitterDateIsAuthorDate.Enabled.Should().BeFalse();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Ignore_date_uncheck_enables_all_options_if_interactive_checked()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();
accessor.chkInteractive.Checked = true;
accessor.chkIgnoreDate.Checked = true;

accessor.chkIgnoreDate.Checked = false;

accessor.chkInteractive.Enabled.Should().BeTrue();
accessor.chkPreserveMerges.Enabled.Should().BeTrue();
accessor.chkAutosquash.Enabled.Should().BeTrue();
accessor.chkCommitterDateIsAuthorDate.Enabled.Should().BeTrue();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Ignore_date_uncheck_enables_all_options_but_autosquash_if_interactive_not_checked()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();
accessor.chkIgnoreDate.Checked = true;

accessor.chkIgnoreDate.Checked = false;

accessor.chkInteractive.Enabled.Should().BeTrue();
accessor.chkPreserveMerges.Enabled.Should().BeTrue();
accessor.chkAutosquash.Enabled.Should().BeFalse();
accessor.chkCommitterDateIsAuthorDate.Enabled.Should().BeTrue();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Committer_date_check_disables_all_other_options()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();

accessor.chkCommitterDateIsAuthorDate.Checked = true;

accessor.chkInteractive.Enabled.Should().BeFalse();
accessor.chkPreserveMerges.Enabled.Should().BeFalse();
accessor.chkAutosquash.Enabled.Should().BeFalse();
accessor.chkIgnoreDate.Enabled.Should().BeFalse();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Committer_date_uncheck_enables_all_options_if_interactive_is_checked()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();
accessor.chkInteractive.Checked = true;
accessor.chkCommitterDateIsAuthorDate.Checked = true;

accessor.chkCommitterDateIsAuthorDate.Checked = false;

accessor.chkInteractive.Enabled.Should().BeTrue();
accessor.chkPreserveMerges.Enabled.Should().BeTrue();
accessor.chkAutosquash.Enabled.Should().BeTrue();
accessor.chkIgnoreDate.Enabled.Should().BeTrue();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

[Test]
public void Committer_date_uncheck_enables_all_options_but_autosquash_if_interactive_not_checked()
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();
accessor.chkCommitterDateIsAuthorDate.Checked = true;

accessor.chkCommitterDateIsAuthorDate.Checked = false;

accessor.chkInteractive.Enabled.Should().BeTrue();
accessor.chkPreserveMerges.Enabled.Should().BeTrue();
accessor.chkAutosquash.Enabled.Should().BeFalse();
accessor.chkIgnoreDate.Enabled.Should().BeTrue();
},
from: "", to: null, onto: null, interactive: false, startRebaseImmediately: false);
}

private void RunFormTest(Action<FormRebase> testDriver, string from, string to, string onto,
bool interactive, bool startRebaseImmediately)
{
RunFormTest(
form =>
{
testDriver(form);
return Task.CompletedTask;
},
from, to, onto, interactive, startRebaseImmediately);
}

private void RunFormTest(Func<FormRebase, Task> testDriverAsync, string from, string to,
string onto, bool interactive, bool startRebaseImmediately)
{
UITest.RunForm(
() =>
{
_commands.StartRebaseDialog(owner: null, from, to, onto, interactive, startRebaseImmediately);
},
testDriverAsync);
}
}
}
Loading