From b17be1e7647ec99e9c599d14e478b754260e4aee Mon Sep 17 00:00:00 2001 From: Brian Freeman Date: Sat, 10 Oct 2020 10:02:22 -0400 Subject: [PATCH] update RemoveFiles to use GetBatchOutput and add unit tests. --- GitCommands/Git/GitModule.cs | 8 ++++---- UnitTests/GitCommands.Tests/GitModuleTests.cs | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/GitCommands/Git/GitModule.cs b/GitCommands/Git/GitModule.cs index 4a0bda73cf4..63dd46ba717 100644 --- a/GitCommands/Git/GitModule.cs +++ b/GitCommands/Git/GitModule.cs @@ -1373,13 +1373,13 @@ public string RemoveFiles(IReadOnlyList files, bool force) return ""; } - return _gitExecutable.GetOutput( + return _gitExecutable.GetBatchOutput( new GitArgumentBuilder("rm") { { force, "--force" }, - "--", - files.Select(f => f.ToPosixPath().Quote()) - }); + "--" + } + .BuildBatchArgumentsForFiles(files)); } /// Tries to start Pageant for the specified remote repo (using the remote's PuTTY key file). diff --git a/UnitTests/GitCommands.Tests/GitModuleTests.cs b/UnitTests/GitCommands.Tests/GitModuleTests.cs index 2c2737cbb8d..6559c2a0980 100644 --- a/UnitTests/GitCommands.Tests/GitModuleTests.cs +++ b/UnitTests/GitCommands.Tests/GitModuleTests.cs @@ -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) {