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

Fix #8188: cannot force push tags #8529

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
22 changes: 21 additions & 1 deletion GitUI/CommandsDialogs/FormPush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private bool PushChanges(IWin32Window owner)

private ForcePushOptions GetForcePushOption()
{
if (ForcePushBranches.Checked)
if (ForcePushBranches.Checked || ForcePushTags.Checked /* tags cannot be pushed using --force-with-lease */)
{
return ForcePushOptions.Force;
}
Expand Down Expand Up @@ -1263,5 +1263,25 @@ private void SetBranchesPushCheckboxesState(Func<DataGridViewRow, bool> willPush
pushCheckBox.Value = willPush(row);
}
}

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

internal readonly struct TestAccessor
{
private readonly FormPush _form;

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

public CheckBox ckForceWithLease => _form.ckForceWithLease;

public CheckBox ForcePushBranches => _form.ForcePushBranches;

public CheckBox ForcePushTags => _form.ForcePushTags;

public ForcePushOptions GetForcePushOption() => _form.GetForcePushOption();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using CommonTestUtils;
using FluentAssertions;
using GitCommands.Git;
using GitUI;
using GitUI.CommandsDialogs;
using NUnit.Framework;

namespace GitExtensions.UITests.CommandsDialogs
{
[Apartment(ApartmentState.STA)]
public class FormPushTests
{
// Created once for the fixture
private ReferenceRepository _referenceRepository;

// Created once for each test
private GitUICommands _commands;

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

_commands = new GitUICommands(_referenceRepository.Module);
}

[TearDown]
public void TearDown()
{
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
_referenceRepository.Dispose();
}

// Note: the DataBindings between ForcePushTags and ForcePushBranches or ckForceWithLease (depending on Git version) do not function in this test environment
[TestCase(false, false, false, ForcePushOptions.DoNotForce)]
[TestCase(false, true, false, ForcePushOptions.Force)]
[TestCase(false, false, true, ForcePushOptions.Force)] // ForcePushTag requires normal force as with-lease is not allowed for tags
[TestCase(false, true, true, ForcePushOptions.Force)]
[TestCase(true, false, false, ForcePushOptions.ForceWithLease)] // would be ForcePushOptions.DoNotForce if DataBindings were working
[TestCase(true, true, false, ForcePushOptions.Force)]
[TestCase(true, false, true, ForcePushOptions.Force)] // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
[TestCase(true, true, true, ForcePushOptions.Force)] // ForcePushBranches and ForcePushTags take precedence over ckForceWithLease
public void Should_choose_correct_force_push_option_for_checkbox_state(
bool forcePushBranchWithLeaseChecked, bool forcePushBranchChecked, bool forcePushTagChecked, ForcePushOptions forcePushOption)
{
RunFormTest(
form =>
{
var accessor = form.GetTestAccessor();

accessor.ForcePushTags.Checked = forcePushTagChecked;
accessor.ckForceWithLease.Checked = forcePushBranchWithLeaseChecked;
accessor.ForcePushBranches.Checked = forcePushBranchChecked;

accessor.GetForcePushOption().Should().Be(forcePushOption);
});
}

private void RunFormTest(Action<FormPush> testDriver)
{
RunFormTest(
form =>
{
testDriver(form);
return Task.CompletedTask;
});
}

private void RunFormTest(Func<FormPush, Task> testDriverAsync)
{
UITest.RunForm(
() =>
{
// False because we haven't performed any actions
Assert.False(_commands.StartPushDialog(owner: null, pushOnShow: false, forceWithLease: false, out _));
},
testDriverAsync);
}
}
}