Skip to content

Commit dffce20

Browse files
committed
Add functional test to repro delete/restore issue
1 parent 05d0118 commit dffce20

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

GVFS/GVFS.FunctionalTests/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public static void Main(string[] args)
2121
NUnitRunner runner = new NUnitRunner(args);
2222
runner.AddGlobalSetupIfNeeded("GVFS.FunctionalTests.GlobalSetup");
2323

24+
if (runner.HasCustomArg("--debug"))
25+
{
26+
Debugger.Launch();
27+
}
28+
2429
if (runner.HasCustomArg("--no-shared-gvfs-cache"))
2530
{
2631
Console.WriteLine("Running without a shared git object cache");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using GVFS.FunctionalTests.Properties;
2+
using NUnit.Framework;
3+
4+
namespace GVFS.FunctionalTests.Tests.GitCommands
5+
{
6+
/// <summary>
7+
/// This class is used to reproduce corruption scenarios in the GVFS virtual projection.
8+
/// </summary>
9+
[Category(Categories.GitCommands)]
10+
[TestFixtureSource(typeof(GitRepoTests), nameof(GitRepoTests.ValidateWorkingTree))]
11+
public class CorruptionReproTests : GitRepoTests
12+
{
13+
public CorruptionReproTests(Settings.ValidateWorkingTreeMode validateWorkingTree)
14+
: base(enlistmentPerTest: true, validateWorkingTree: validateWorkingTree)
15+
{
16+
}
17+
18+
/// <summary>
19+
/// Reproduction of a reported issue:
20+
/// Restoring a file after its parent directory was deleted fails with
21+
/// "fatal: could not unlink 'path\to\': Directory not empty"
22+
/// </summary>
23+
[TestCase]
24+
public void RestoreAfterDeleteNesteredDirectory()
25+
{
26+
// Delete a directory with nested subdirectories and files.
27+
this.ValidateNonGitCommand("cmd.exe", "/c \"rmdir /s /q GVFlt_DeleteFileTest\"");
28+
29+
// Restore the working directory.
30+
this.ValidateGitCommand("restore .");
31+
32+
this.FilesShouldMatchCheckoutOfSourceBranch();
33+
}
34+
}
35+
}

GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitRepoTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,23 @@ protected void ValidateGitCommand(string command, params object[] args)
269269
args);
270270
}
271271

272+
protected void ValidateNonGitCommand(string command, string args = "", bool ignoreErrors = false, bool checkStatus = true)
273+
{
274+
string controlRepoRoot = this.ControlGitRepo.RootPath;
275+
string gvfsRepoRoot = this.Enlistment.RepoRoot;
276+
277+
ProcessResult expectedResult = ProcessHelper.Run(command, args, controlRepoRoot);
278+
ProcessResult actualResult = ProcessHelper.Run(command, args, gvfsRepoRoot);
279+
if (!ignoreErrors)
280+
{
281+
GitHelpers.ErrorsShouldMatch(command, expectedResult, actualResult);
282+
}
283+
if (checkStatus)
284+
{
285+
this.ValidateGitCommand("status");
286+
}
287+
}
288+
272289
protected void ChangeMode(string filePath, ushort mode)
273290
{
274291
string virtualFile = Path.Combine(this.Enlistment.RepoRoot, filePath);

GVFS/GVFS.FunctionalTests/Tools/ProcessHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ namespace GVFS.FunctionalTests.Tools
66
public static class ProcessHelper
77
{
88
public static ProcessResult Run(string fileName, string arguments)
9+
{
10+
return Run(fileName, arguments, null);
11+
}
12+
13+
public static ProcessResult Run(string fileName, string arguments, string workingDirectory)
914
{
1015
ProcessStartInfo startInfo = new ProcessStartInfo();
1116
startInfo.UseShellExecute = false;
@@ -14,6 +19,10 @@ public static ProcessResult Run(string fileName, string arguments)
1419
startInfo.CreateNoWindow = true;
1520
startInfo.FileName = fileName;
1621
startInfo.Arguments = arguments;
22+
if (!string.IsNullOrEmpty(workingDirectory))
23+
{
24+
startInfo.WorkingDirectory = workingDirectory;
25+
}
1726

1827
return Run(startInfo);
1928
}

0 commit comments

Comments
 (0)