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

[Linux] Convert tests and repair jobs to use backing root #1411

Merged
merged 3 commits into from
Aug 19, 2019
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
29 changes: 19 additions & 10 deletions GVFS/GVFS.FunctionalTests/Tests/EnlistmentPerFixture/MountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void MountCopiesMissingReadObjectHook()
{
this.Enlistment.UnmountGVFS();

string readObjectPath = this.Enlistment.GetVirtualPathTo(".git", "hooks", "read-object" + Settings.Default.BinaryFileNameExtension);
string readObjectPath = this.Enlistment.GetDotGitPath("hooks", "read-object" + Settings.Default.BinaryFileNameExtension);
readObjectPath.ShouldBeAFile(this.fileSystem);
this.fileSystem.DeleteFile(readObjectPath);
readObjectPath.ShouldNotExistOnDisk(this.fileSystem);
Expand All @@ -76,7 +76,7 @@ public void MountSetsCoreHooksPath()
.ShouldBeTrue();

this.Enlistment.MountGVFS();
string expectedHooksPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "hooks");
string expectedHooksPath = this.Enlistment.GetDotGitPath("hooks");
expectedHooksPath = GitHelpers.ConvertPathToGitFormat(expectedHooksPath);

GitProcess.Invoke(
Expand Down Expand Up @@ -198,7 +198,7 @@ public void MountRegeneratesAlternatesFileWhenMissingGitObjectsRoot()

string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(this.Enlistment.DotGVFSRoot).ShouldNotBeNull();

string alternatesFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "objects", "info", "alternates");
string alternatesFilePath = this.Enlistment.GetDotGitPath("objects", "info", "alternates");
alternatesFilePath.ShouldBeAFile(this.fileSystem).WithContents(objectsRoot);
this.fileSystem.WriteAllText(alternatesFilePath, "Z:\\invalidPath");

Expand All @@ -214,7 +214,7 @@ public void MountRegeneratesAlternatesFileWhenMissingFromDisk()

string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(this.Enlistment.DotGVFSRoot).ShouldNotBeNull();

string alternatesFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "objects", "info", "alternates");
string alternatesFilePath = this.Enlistment.GetDotGitPath("objects", "info", "alternates");
alternatesFilePath.ShouldBeAFile(this.fileSystem).WithContents(objectsRoot);
this.fileSystem.DeleteFile(alternatesFilePath);

Expand Down Expand Up @@ -345,17 +345,26 @@ private void MountShouldFail(string expectedErrorMessage, string mountWorkingDir
private class MountSubfolders
{
public const string MountFolders = "Folders";
private static object[] mountFolders =
{
new object[] { string.Empty },
new object[] { "GVFS" },
};

public static object[] Folders
{
get
{
return mountFolders;
// On Linux, an unmounted repository is completely empty, so we must
// only try to mount from the root of the virtual path.

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return new object[] { new object[] { string.Empty } };
}
else
{
return new object[]
{
new object[] { string.Empty },
new object[] { "GVFS" },
};
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void ExpandOneTempPack(bool copyPackBackToPackDirectory)
using (FileStream packFileStream = File.OpenRead(packFile))
{
string output = GitProcess.InvokeProcess(
this.Enlistment.RepoRoot,
this.Enlistment.RepoBackingRoot,
"unpack-objects",
new Dictionary<string, string>() { { "GIT_OBJECT_DIRECTORY", this.GitObjectRoot } },
inputStream: packFileStream).Output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void FixesCorruptHeadSha()
{
this.Enlistment.UnmountGVFS();

string headFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "HEAD");
string headFilePath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "HEAD");
File.WriteAllText(headFilePath, "0000");
this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when HEAD is corrupt");

Expand All @@ -39,7 +39,7 @@ public void FixesCorruptHeadSymRef()
{
this.Enlistment.UnmountGVFS();

string headFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "HEAD");
string headFilePath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "HEAD");
File.WriteAllText(headFilePath, "ref: refs");
this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when HEAD is corrupt");

Expand All @@ -53,7 +53,7 @@ public void FixesMissingGitIndex()
{
this.Enlistment.UnmountGVFS();

string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "index");
string gitIndexPath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "index");
File.Delete(gitIndexPath);
this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when git index is missing");

Expand All @@ -67,7 +67,7 @@ public void FixesGitIndexCorruptedWithBadData()
{
this.Enlistment.UnmountGVFS();

string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "index");
string gitIndexPath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "index");
this.CreateCorruptIndexAndRename(
gitIndexPath,
(current, temp) =>
Expand All @@ -90,7 +90,7 @@ public void FixesGitIndexContainingAllNulls()
{
this.Enlistment.UnmountGVFS();

string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "index");
string gitIndexPath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "index");

// Set the contents of the index file to gitIndexPath NULL
this.CreateCorruptIndexAndRename(
Expand All @@ -114,7 +114,7 @@ public void FixesGitIndexCorruptedByTruncation()
{
this.Enlistment.UnmountGVFS();

string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "index");
string gitIndexPath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "index");

// Truncate the contents of the index
this.CreateCorruptIndexAndRename(
Expand All @@ -141,15 +141,15 @@ public void FixesCorruptGitConfig()
{
this.Enlistment.UnmountGVFS();

string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "config");
string gitIndexPath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "config");
File.WriteAllText(gitIndexPath, "[cor");

this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when git config is missing");

this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.Repair(confirm: true);
ProcessResult result = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "remote add origin " + this.Enlistment.RepoUrl);
ProcessResult result = GitProcess.InvokeProcess(this.Enlistment.RepoBackingRoot, "remote add origin " + this.Enlistment.RepoUrl);
result.ExitCode.ShouldEqual(0, result.Errors);
this.Enlistment.MountGVFS();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public void CheckoutBranchWithOpenHandleBlockingProjectionDeleteAndRepoMetdataUp
this.ControlGitRepo.Fetch(GitRepoTests.ConflictTargetBranch);

this.Enlistment.UnmountGVFS();
string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "index");
string gitIndexPath = Path.Combine(this.Enlistment.RepoBackingRoot, ".git", "index");
CopyIndexAndRename(gitIndexPath);
this.Enlistment.MountGVFS();

Expand Down
27 changes: 26 additions & 1 deletion GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ public string RepoUrl

public string LocalCacheRoot { get; }

public string RepoBackingRoot
{
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Path.Combine(this.EnlistmentRoot, ".vfsforgit/lower");
}
else
{
return this.RepoRoot;
}
}
}

public string RepoRoot
{
get { return Path.Combine(this.EnlistmentRoot, "src"); }
Expand Down Expand Up @@ -279,10 +294,20 @@ public string GetVirtualPathTo(params string[] pathParts)
return Path.Combine(this.RepoRoot, Path.Combine(pathParts));
}

public string GetBackingPathTo(params string[] pathParts)
{
return Path.Combine(this.RepoBackingRoot, Path.Combine(pathParts));
}

public string GetDotGitPath(params string[] pathParts)
{
return this.GetBackingPathTo(TestConstants.DotGit.Root, Path.Combine(pathParts));
}

public string GetObjectPathTo(string objectHash)
{
return Path.Combine(
this.RepoRoot,
this.RepoBackingRoot,
TestConstants.DotGit.Objects.Root,
objectHash.Substring(0, 2),
objectHash.Substring(2));
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS/RepairJobs/GitConfigRepairJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public override IssueType HasIssue(List<string> messages)

public override FixResult TryFixIssues(List<string> messages)
{
string configPath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Config);
string configPath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Config);
string configBackupPath;
if (!this.TryRenameToBackupFile(configPath, out configBackupPath, messages))
{
Expand Down
16 changes: 8 additions & 8 deletions GVFS/GVFS/RepairJobs/GitHeadRepairJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override FixResult TryFixIssues(List<string> messages)

try
{
string refPath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Head);
string refPath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Head);
File.WriteAllText(refPath, refLog.TargetSha);
}
catch (IOException ex)
Expand Down Expand Up @@ -82,7 +82,7 @@ public override FixResult TryFixIssues(List<string> messages)
/// <param name="fullSymbolicRef">A full symbolic ref name. eg. HEAD, refs/remotes/origin/HEAD, refs/heads/master</param>
private static bool TryReadLastRefLogEntry(Enlistment enlistment, string fullSymbolicRef, out RefLogEntry refLog, out string error)
{
string refLogPath = Path.Combine(enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Logs.Root, fullSymbolicRef);
string refLogPath = Path.Combine(enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Logs.Root, fullSymbolicRef);
if (!File.Exists(refLogPath))
{
refLog = null;
Expand Down Expand Up @@ -112,7 +112,7 @@ private static bool TryReadLastRefLogEntry(Enlistment enlistment, string fullSym

private static bool TryParseHead(Enlistment enlistment, List<string> messages)
{
string refPath = Path.Combine(enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Head);
string refPath = Path.Combine(enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Head);
if (!File.Exists(refPath))
{
messages.Add("Could not find ref file for '" + GVFSConstants.DotGit.Head + "'");
Expand Down Expand Up @@ -145,35 +145,35 @@ private bool CanBeRepaired(List<string> messages)
{
Func<string, string> createErrorMessage = operation => string.Format("Can't repair HEAD while a {0} operation is in progress", operation);

string rebasePath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.RebaseApply);
string rebasePath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.RebaseApply);
if (Directory.Exists(rebasePath))
{
messages.Add(createErrorMessage("rebase"));
return false;
}

string mergeHeadPath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.MergeHead);
string mergeHeadPath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.MergeHead);
if (File.Exists(mergeHeadPath))
{
messages.Add(createErrorMessage("merge"));
return false;
}

string bisectStartPath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.BisectStart);
string bisectStartPath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.BisectStart);
if (File.Exists(bisectStartPath))
{
messages.Add(createErrorMessage("bisect"));
return false;
}

string cherrypickHeadPath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.CherryPickHead);
string cherrypickHeadPath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.CherryPickHead);
if (File.Exists(cherrypickHeadPath))
{
messages.Add(createErrorMessage("cherry-pick"));
return false;
}

string revertHeadPath = Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.RevertHead);
string revertHeadPath = Path.Combine(this.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.RevertHead);
if (File.Exists(revertHeadPath))
{
messages.Add(createErrorMessage("revert"));
Expand Down