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

updated removeFiles to use GetBatchOutput and added unit tests #8527

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,13 +1373,13 @@ public string RemoveFiles(IReadOnlyList<string> files, bool force)
return "";
}

return _gitExecutable.GetOutput(
return _gitExecutable.GetBatchOutput(
new GitArgumentBuilder("rm")
{
{ force, "--force" },
"--",
files.Select(f => f.ToPosixPath().Quote())
});
"--"
}
.BuildBatchArgumentsForFiles(files));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] incorrect indentation

}

/// <summary>Tries to start Pageant for the specified remote repo (using the remote's PuTTY key file).</summary>
Expand Down
20 changes: 20 additions & 0 deletions UnitTests/GitCommands.Tests/GitModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,26 @@ public void ResetFiles_should_work_as_expected(string[] files, string args)
}
}

[TestCase(new string[] { "abc", "def" }, "rm -- \"abc\" \"def\"")]
public void RemoveFiles_shouldWorkAsExpected(string[] files, string args)
{
// Real GitModule is need to access AppSettings.GitCommand static property, avoid exception with dummy GitModule
using (var moduleTestHelper = new GitModuleTestHelper())
{
var gitModule = GetGitModuleWithExecutable(_executable, module: moduleTestHelper.Module);
string dummyCommandOutput = "The answer is 42. Just check that the Git arguments are as expected.";
_executable.StageOutput(args, dummyCommandOutput);
var result = gitModule.RemoveFiles(files.ToList(), false);
Assert.AreEqual(dummyCommandOutput, result);
}
}

[TestCase(new string[] { }, "")]
public void RemoveFiles_should_handle_empty_list(string[] files, string expectedOutput)
{
Assert.AreEqual(expectedOutput, _gitModule.RemoveFiles(files.ToList(), false));
}

[TestCaseSource(nameof(BatchUnstageFilesTestCases))]
public void BatchUnstageFiles_should_work_as_expected(GitItemStatus[] files, string[] args, bool expectedResult)
{
Expand Down