Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ public GitFilesTests(FileSystemRunner fileSystem)
}

[TestCase, Order(1)]
[Category(Categories.Mac.M2TODO)]
public void CreateFileTest()
{
string fileName = "file1.txt";
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, fileName);
this.fileSystem.WriteAllText(this.Enlistment.GetVirtualPathTo(fileName), "Some content here");

this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

this.Enlistment.GetVirtualPathTo(fileName).ShouldBeAFile(this.fileSystem).WithContents("Some content here");
GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, fileName);
this.Enlistment.GetVirtualPathTo(fileName).ShouldBeAFile(this.fileSystem).WithContents("Some content here");

string emptyFileName = "file1empty.txt";
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, emptyFileName);
this.fileSystem.CreateEmptyFile(this.Enlistment.GetVirtualPathTo(emptyFileName));
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");
GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, emptyFileName);
this.Enlistment.GetVirtualPathTo(fileName).ShouldBeAFile(this.fileSystem);
}

[TestCase, Order(2)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,31 @@ public void GitStatus()
}

[TestCase, Order(2)]
[Category(Categories.Mac.M2TODO)]
public void GitStatusAfterNewFile()
{
string filename = "new.cs";
string filePath = this.Enlistment.GetVirtualPathTo(filename);

this.fileSystem.WriteAllText(this.Enlistment.GetVirtualPathTo(filename), this.testFileContents);
this.fileSystem.WriteAllText(filePath, this.testFileContents);

this.Enlistment.GetVirtualPathTo(filename).ShouldBeAFile(this.fileSystem).WithContents(this.testFileContents);
filePath.ShouldBeAFile(this.fileSystem).WithContents(this.testFileContents);

GitHelpers.CheckGitCommandAgainstGVFSRepo(
this.Enlistment.RepoRoot,
"status",
"On branch " + Properties.Settings.Default.Commitish,
"Untracked files:",
filename);

this.fileSystem.DeleteFile(filePath);
}

[TestCase, Order(3)]
[Category(Categories.Mac.M2TODO)]
public void GitStatusAfterFileNameCaseChange()
{
string oldFilename = "new.cs";
this.Enlistment.GetVirtualPathTo(oldFilename).ShouldBeAFile(this.fileSystem);
this.EnsureTestFileExists(oldFilename);

string newFilename = "New.cs";
this.fileSystem.MoveFile(this.Enlistment.GetVirtualPathTo(oldFilename), this.Enlistment.GetVirtualPathTo(newFilename));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace GVFS.FunctionalTests.Tests.EnlistmentPerTestCase
{
[TestFixture]
//// TODO(Mac): Enable for M2 once notifications are working
//// [Category(Categories.Mac.M2)]
[Category(Categories.Mac.M2TODO)]
public class PersistedModifiedPathsTests : TestsWithEnlistmentPerTestCase
{
private static readonly string FileToAdd = Path.Combine("GVFS", "TestAddFile.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace GVFS.FunctionalTests.Tests.GitCommands
{
[TestFixture]
[Category(Categories.GitCommands)]
[Category(Categories.Mac.M3)]
public class AddStageTests : GitRepoTests
{
public AddStageTests() : base(enlistmentPerTest: false)
Expand Down
52 changes: 33 additions & 19 deletions GVFS/GVFS.FunctionalTests/Tests/GitCommands/GitCommandsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,48 +88,56 @@ public void RenameCurrentBranchTest()
}

[TestCase]
[Category(Categories.Mac.M2)]
public void UntrackedFileTest()
{
this.BasicCommit(this.CreateFile, addCommand: "add .");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void UntrackedEmptyFileTest()
{
this.BasicCommit(this.CreateEmptyFile, addCommand: "add .");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void UntrackedFileAddAllTest()
{
this.BasicCommit(this.CreateFile, addCommand: "add --all");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void UntrackedEmptyFileAddAllTest()
{
this.BasicCommit(this.CreateEmptyFile, addCommand: "add --all");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void StageUntrackedFileTest()
{
this.BasicCommit(this.CreateFile, addCommand: "stage .");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void StageUntrackedEmptyFileTest()
{
this.BasicCommit(this.CreateEmptyFile, addCommand: "stage .");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void StageUntrackedFileAddAllTest()
{
this.BasicCommit(this.CreateFile, addCommand: "stage --all");
}

[TestCase]
[Category(Categories.Mac.M2)]
public void StageUntrackedEmptyFileAddAllTest()
{
this.BasicCommit(this.CreateEmptyFile, addCommand: "stage --all");
Expand Down Expand Up @@ -234,27 +242,33 @@ public void DeleteFolderCommitChangesSwitchBranchSwitchBackTest()
}

[TestCase]
[Category(Categories.Mac.M2)]
public void DeleteFilesWithNameAheadOfDot()
{
this.FolderShouldExistAndHaveFile("GitCommandsTests\\DeleteFileTests\\1", "#test");
this.DeleteFile("GitCommandsTests\\DeleteFileTests\\1\\#test");
this.FolderShouldExistAndBeEmpty("GitCommandsTests\\DeleteFileTests\\1");

this.FolderShouldExistAndHaveFile("GitCommandsTests\\DeleteFileTests\\2", "$test");
this.DeleteFile("GitCommandsTests\\DeleteFileTests\\2\\$test");
this.FolderShouldExistAndBeEmpty("GitCommandsTests\\DeleteFileTests\\2");

this.FolderShouldExistAndHaveFile("GitCommandsTests\\DeleteFileTests\\3", ")");
this.DeleteFile("GitCommandsTests\\DeleteFileTests\\3\\)");
this.FolderShouldExistAndBeEmpty("GitCommandsTests\\DeleteFileTests\\3");

this.FolderShouldExistAndHaveFile("GitCommandsTests\\DeleteFileTests\\4", "+.test");
this.DeleteFile("GitCommandsTests\\DeleteFileTests\\4\\+.test");
this.FolderShouldExistAndBeEmpty("GitCommandsTests\\DeleteFileTests\\4");

this.FolderShouldExistAndHaveFile("GitCommandsTests\\DeleteFileTests\\5", "-.test");
this.DeleteFile("GitCommandsTests\\DeleteFileTests\\5\\-.test");
this.FolderShouldExistAndBeEmpty("GitCommandsTests\\DeleteFileTests\\5");
string folder = Path.Combine("GitCommandsTests", "DeleteFileTests", "1");
this.FolderShouldExistAndHaveFile(folder, "#test");
this.DeleteFile(Path.Combine(folder, "#test"));
this.FolderShouldExistAndBeEmpty(folder);

folder = Path.Combine("GitCommandsTests", "DeleteFileTests", "2");
this.FolderShouldExistAndHaveFile(folder, "$test");
this.DeleteFile(Path.Combine(folder, "$test"));
this.FolderShouldExistAndBeEmpty(folder);

folder = Path.Combine("GitCommandsTests", "DeleteFileTests", "3");
this.FolderShouldExistAndHaveFile(folder, ")");
this.DeleteFile(Path.Combine(folder, ")"));
this.FolderShouldExistAndBeEmpty(folder);

folder = Path.Combine("GitCommandsTests", "DeleteFileTests", "4");
this.FolderShouldExistAndHaveFile(folder, "+.test");
this.DeleteFile(Path.Combine(folder, "+.test"));
this.FolderShouldExistAndBeEmpty(folder);

folder = Path.Combine("GitCommandsTests", "DeleteFileTests", "5");
this.FolderShouldExistAndHaveFile(folder, "-.test");
this.DeleteFile(Path.Combine(folder, "-.test"));
this.FolderShouldExistAndBeEmpty(folder);

this.ValidateGitCommand("status");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace GVFS.FunctionalTests.Tests.GitCommands
{
[TestFixture]
[Category(Categories.Mac.M3)]
public class HashObjectTests : GitRepoTests
{
public HashObjectTests() : base(enlistmentPerTest: false)
Expand Down
36 changes: 36 additions & 0 deletions GVFS/GVFS.Platform.Mac/MacFileSystemVirtualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected override bool TryStart(out string error)
this.virtualizationInstance.OnGetFileStream = this.OnGetFileStream;
this.virtualizationInstance.OnFileModified = this.OnFileModified;
this.virtualizationInstance.OnPreDelete = this.OnPreDelete;
this.virtualizationInstance.OnNewFileCreated = this.OnNewFileCreated;

uint threadCount = (uint)Environment.ProcessorCount * 2;

Expand Down Expand Up @@ -312,6 +313,41 @@ private Result OnPreDelete(string relativePath, bool isDirectory)
return Result.Success;
}

private void OnNewFileCreated(string relativePath, bool isDirectory)
{
try
{
if (!Virtualization.FileSystemCallbacks.IsPathInsideDotGit(relativePath))
{
if (isDirectory)
{
GitCommandLineParser gitCommand = new GitCommandLineParser(this.Context.Repository.GVFSLock.GetLockedGitCommand());
if (gitCommand.IsValidGitCommand)
{
// TODO(Mac): Ensure that when git creates a folder all files\folders within that folder are written to disk
EventMetadata metadata = this.CreateEventMetadata(relativePath);
metadata.Add("isDirectory", isDirectory);
this.Context.Tracer.RelatedWarning(metadata, $"{nameof(this.OnNewFileCreated)}: Git created a folder, currently an unsupported scenario on Mac");
}
else
{
this.FileSystemCallbacks.OnFolderCreated(relativePath);
}
}
else
{
this.FileSystemCallbacks.OnFileCreated(relativePath);
}
}
}
catch (Exception e)
{
EventMetadata metadata = this.CreateEventMetadata(relativePath, e);
metadata.Add("isDirectory", isDirectory);
this.LogUnhandledExceptionAndExit(nameof(this.OnNewFileCreated), metadata);
}
}

private Result OnEnumerateDirectory(
ulong commandId,
string relativePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public override bool TryStartVirtualizationInstance(Enlistment enlistment, out s
this.virtualizationInstance.OnEnumerateDirectory = this.OnEnumerateDirectory;
this.virtualizationInstance.OnGetFileStream = this.OnGetFileStream;
this.virtualizationInstance.OnFileModified = this.OnFileModified;
this.virtualizationInstance.OnPreDelete = this.OnPreDelete;
this.virtualizationInstance.OnPreDelete = this.OnPreDelete;
this.virtualizationInstance.OnNewFileCreated = this.OnNewFileCreated;

Result result = this.virtualizationInstance.StartVirtualizationInstance(
enlistment.SrcRoot,
Expand Down Expand Up @@ -157,6 +158,11 @@ private Result OnPreDelete(string relativePath, bool isDirectory)
{
Console.WriteLine($"OnPreDelete (isDirectory: {isDirectory}): {relativePath}");
return Result.Success;
}

private void OnNewFileCreated(string relativePath, bool isDirectory)
{
Console.WriteLine($"OnNewFileCreated (isDirectory: {isDirectory}): {relativePath}");
}

private static byte[] ToVersionIdByteArray(byte version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ public override bool TryStartVirtualizationInstance(Enlistment enlistment, out s
this.virtualizationInstance.OnGetPlaceholderInformation = this.GetPlaceholderInformation;
this.virtualizationInstance.OnGetFileStream = this.GetFileStream;
this.virtualizationInstance.OnNotifyPreDelete = this.OnPreDelete;
this.virtualizationInstance.OnNotifyNewFileCreated = this.OnNewFileCreated;
this.virtualizationInstance.OnNotifyFileHandleClosedFileModifiedOrDeleted = this.OnFileModifiedOrDeleted;

uint threadCount = (uint)Environment.ProcessorCount * 2;

NotificationMapping[] notificationMappings = new NotificationMapping[]
{
new NotificationMapping(NotificationType.PreDelete | NotificationType.FileHandleClosedFileModified, string.Empty),
new NotificationMapping(
NotificationType.NewFileCreated |
NotificationType.PreDelete |
NotificationType.FileHandleClosedFileModified,
string.Empty),
};

HResult result = this.virtualizationInstance.StartVirtualizationInstance(
Expand Down Expand Up @@ -290,6 +295,18 @@ private HResult OnPreDelete(string relativePath, bool isDirectory)
return HResult.Ok;
}

private void OnNewFileCreated(
string relativePath,
bool isDirectory,
uint desiredAccess,
uint shareMode,
uint createDisposition,
uint createOptions,
ref NotificationType notificationMask)
{
Console.WriteLine($"OnNewFileCreated (isDirectory: {isDirectory}): {relativePath}");
}

private void OnFileModifiedOrDeleted(string relativePath, bool isDirectory, bool isFileModified, bool isFileDeleted)
{
// To keep WindowsFileSystemVirtualizer in sync with MacFileSystemVirtualizer we're only registering for
Expand Down
Loading