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
6 changes: 3 additions & 3 deletions GVFS/FastFetch/CheckoutPrefetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void Prefetch(string branchOrCommit, bool isBranch)
commitToFetch = branchOrCommit;
}

using (new IndexLock(this.Enlistment.EnlistmentRoot, this.Tracer))
using (new IndexLock(this.Enlistment.PrimaryEnlistmentRoot, this.Tracer))
{
this.DownloadMissingCommit(commitToFetch, this.GitObjects);

Expand Down Expand Up @@ -124,7 +124,7 @@ public override void Prefetch(string branchOrCommit, bool isBranch)
if (!indexGen.HasFailures)
{
Index newIndex = new Index(
this.Enlistment.EnlistmentRoot,
this.Enlistment.PrimaryEnlistmentRoot,
this.Tracer,
indexGen.TemporaryIndexFilePath,
readOnly: false);
Expand Down Expand Up @@ -200,7 +200,7 @@ private Index GetSourceIndex()

if (File.Exists(indexPath))
{
Index output = new Index(this.Enlistment.EnlistmentRoot, this.Tracer, indexPath, readOnly: true);
Index output = new Index(this.Enlistment.PrimaryEnlistmentRoot, this.Tracer, indexPath, readOnly: true);
output.Parse();
return output;
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/FastFetch/FastFetchVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private int ExecuteWithExitCode()
CacheServerInfo cacheServer = new CacheServerInfo(this.GetRemoteUrl(enlistment), null);

tracer.WriteStartEvent(
enlistment.EnlistmentRoot,
enlistment.PrimaryEnlistmentRoot,
enlistment.RepoUrl,
cacheServer.Url,
new EventMetadata
Expand Down
2 changes: 1 addition & 1 deletion GVFS/FastFetch/GitEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private GitEnlistment(string repoRoot, string gitBinPath)

public string FastFetchLogRoot
{
get { return Path.Combine(this.EnlistmentRoot, GVFSConstants.DotGit.Root, ".fastfetch"); }
get { return Path.Combine(this.PrimaryEnlistmentRoot, GVFSConstants.DotGit.Root, ".fastfetch"); }
}

public static GitEnlistment CreateFromCurrentDirectory(string gitBinPath)
Expand Down
4 changes: 2 additions & 2 deletions GVFS/GVFS.Common/Database/GVFSDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class GVFSDatabase : IGVFSConnectionPool, IDisposable
private IDbConnectionFactory connectionFactory;
private BlockingCollection<IDbConnection> connectionPool;

public GVFSDatabase(PhysicalFileSystem fileSystem, string enlistmentRoot, IDbConnectionFactory connectionFactory, int initialPooledConnections = InitialPooledConnections)
public GVFSDatabase(PhysicalFileSystem fileSystem, string dotGVFSRoot, IDbConnectionFactory connectionFactory, int initialPooledConnections = InitialPooledConnections)
{
this.connectionPool = new BlockingCollection<IDbConnection>();
this.databasePath = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot, GVFSConstants.DotGVFS.Databases.VFSForGit);
this.databasePath = Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.VFSForGit);
this.connectionFactory = connectionFactory;

string folderPath = Path.GetDirectoryName(this.databasePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override bool TryUpgrade(ITracer tracer, string enlistmentRoot)
}

using (placeholderList)
using (GVFSDatabase database = new GVFSDatabase(fileSystem, enlistmentRoot, new SqliteDatabase()))
using (GVFSDatabase database = new GVFSDatabase(fileSystem, Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot), new SqliteDatabase()))
{
PlaceholderTable placeholders = new PlaceholderTable(database);
List<IPlaceholderData> oldPlaceholderEntries = placeholderList.GetAllEntries();
Expand Down
4 changes: 2 additions & 2 deletions GVFS/GVFS.Common/Enlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected Enlistment(
throw new ArgumentException("Path to git.exe must be set");
}

this.EnlistmentRoot = enlistmentRoot;
this.PrimaryEnlistmentRoot = enlistmentRoot;
this.WorkingDirectoryRoot = workingDirectoryRoot;
this.WorkingDirectoryBackingRoot = workingDirectoryBackingRoot;
this.DotGitRoot = Path.Combine(this.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Root);
Expand Down Expand Up @@ -52,7 +52,7 @@ protected Enlistment(
this.Authentication = authentication ?? new GitAuthentication(gitProcess, this.RepoUrl);
}

public string EnlistmentRoot { get; }
public string PrimaryEnlistmentRoot { get; }

// Path to the root of the working (i.e. "src") directory.
// On platforms where the contents of the working directory are stored
Expand Down
4 changes: 2 additions & 2 deletions GVFS/GVFS.Common/FileSystem/HooksInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private static bool TryUpdateHook(
metadata.Add(nameof(installedHookPath), installedHookPath);
metadata.Add("Exception", e.ToString());
context.Tracer.RelatedError(metadata, "Failed to compare " + hookName + " version");
errorMessage = "Error comparing " + hookName + " versions. " + ConsoleHelper.GetGVFSLogMessage(context.Enlistment.EnlistmentRoot);
errorMessage = "Error comparing " + hookName + " versions. " + ConsoleHelper.GetGVFSLogMessage(context.Enlistment.WorkingDirectoryRoot);
return false;
}
}
Expand All @@ -248,7 +248,7 @@ private static bool TryUpdateHook(
metadata.Add(nameof(installedHookPath), installedHookPath);
metadata.Add("Exception", e.ToString());
context.Tracer.RelatedError(metadata, "Failed to copy " + hookName + " to enlistment");
errorMessage = "Error copying " + hookName + " to enlistment. " + ConsoleHelper.GetGVFSLogMessage(context.Enlistment.EnlistmentRoot);
errorMessage = "Error copying " + hookName + " to enlistment. " + ConsoleHelper.GetGVFSLogMessage(context.Enlistment.WorkingDirectoryRoot);
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions GVFS/GVFS.Common/GVFSEnlistment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public GVFSEnlistment(string enlistmentRoot, string repoUrl, string gitBinPath,
flushFileBuffersForPacks: true,
authentication: authentication)
{
this.NamedPipeName = GVFSPlatform.Instance.GetNamedPipeName(this.EnlistmentRoot);
this.DotGVFSRoot = Path.Combine(this.EnlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot);
this.NamedPipeName = GVFSPlatform.Instance.GetNamedPipeName(this.PrimaryEnlistmentRoot);
this.DotGVFSRoot = Path.Combine(this.PrimaryEnlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot);
this.GitStatusCacheFolder = Path.Combine(this.DotGVFSRoot, GVFSConstants.DotGVFS.GitStatusCache.Name);
this.GitStatusCachePath = Path.Combine(this.DotGVFSRoot, GVFSConstants.DotGVFS.GitStatusCache.CachePath);
this.GVFSLogsRoot = Path.Combine(this.EnlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot, GVFSConstants.DotGVFS.LogName);
this.GVFSLogsRoot = Path.Combine(this.DotGVFSRoot, GVFSConstants.DotGVFS.LogName);
this.LocalObjectsRoot = Path.Combine(this.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Objects.Root);
}

Expand Down
8 changes: 7 additions & 1 deletion GVFS/GVFS.Common/Git/GitRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
private PhysicalFileSystem fileSystem;
private LibGit2RepoInvoker libgit2RepoInvoker;
private Enlistment enlistment;
private string dotGVFSRoot;

public GitRepo(ITracer tracer, Enlistment enlistment, PhysicalFileSystem fileSystem, Func<LibGit2Repo> repoFactory = null)
{
this.tracer = tracer;
this.enlistment = enlistment;
this.fileSystem = fileSystem;

// Resolve the per-worktree .gvfs root if available; otherwise
// derive from EnlistmentRoot (primary enlistments).
this.dotGVFSRoot = (enlistment as GVFSEnlistment)?.DotGVFSRoot
?? Path.Combine(enlistment.PrimaryEnlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot);

this.GVFSLock = new GVFSLock(tracer);

this.libgit2RepoInvoker = new LibGit2RepoInvoker(
Expand Down Expand Up @@ -147,7 +153,7 @@
size = 0;

byte[] buffer = new byte[5];
input.Read(buffer, 0, buffer.Length);

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Release)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Release)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Release)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Release)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Debug)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Debug)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Debug)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)

Check warning on line 156 in GVFS/GVFS.Common/Git/GitRepo.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test (Debug)

Avoid inexact read with 'System.IO.Stream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
if (!Enumerable.SequenceEqual(buffer, LooseBlobHeader))
{
return false;
Expand Down Expand Up @@ -240,7 +246,7 @@
{
if (corruptLooseObject)
{
string corruptBlobsFolderPath = Path.Combine(this.enlistment.EnlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot, GVFSConstants.DotGVFS.CorruptObjectsName);
string corruptBlobsFolderPath = Path.Combine(this.dotGVFSRoot, GVFSConstants.DotGVFS.CorruptObjectsName);
string corruptBlobPath = Path.Combine(corruptBlobsFolderPath, Path.GetRandomFileName());

EventMetadata metadata = new EventMetadata();
Expand Down
5 changes: 2 additions & 3 deletions GVFS/GVFS.Common/Git/RequiredGitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class RequiredGitConfig
/// Returns the dictionary of required git config settings for a GVFS enlistment.
/// These settings override any existing local configuration values.
/// </summary>
public static Dictionary<string, string> GetRequiredSettings(Enlistment enlistment)
public static Dictionary<string, string> GetRequiredSettings(GVFSEnlistment enlistment)
{
string expectedHooksPath = Path.Combine(enlistment.DotGitRoot, GVFSConstants.DotGit.Hooks.RootName);
expectedHooksPath = Paths.ConvertPathToGitFormat(expectedHooksPath);
Expand All @@ -31,8 +31,7 @@ public static Dictionary<string, string> GetRequiredSettings(Enlistment enlistme
if (!GVFSEnlistment.IsUnattended(tracer: null) && GVFSPlatform.Instance.IsGitStatusCacheSupported())
{
gitStatusCachePath = Path.Combine(
enlistment.EnlistmentRoot,
GVFSPlatform.Instance.Constants.DotGVFSRoot,
enlistment.DotGVFSRoot,
GVFSConstants.DotGVFS.GitStatusCache.CachePath);

gitStatusCachePath = Paths.ConvertPathToGitFormat(gitStatusCachePath);
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/HealthCalculator/EnlistmentPathData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void LoadPlaceholdersFromDatabase(GVFSEnlistment enlistment)
List<IPlaceholderData> filePlaceholders = new List<IPlaceholderData>();
List<IPlaceholderData> folderPlaceholders = new List<IPlaceholderData>();

using (GVFSDatabase database = new GVFSDatabase(new PhysicalFileSystem(), enlistment.EnlistmentRoot, new SqliteDatabase()))
using (GVFSDatabase database = new GVFSDatabase(new PhysicalFileSystem(), enlistment.DotGVFSRoot, new SqliteDatabase()))
{
PlaceholderTable placeholderTable = new PlaceholderTable(database);
placeholderTable.GetAllEntries(out filePlaceholders, out folderPlaceholders);
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/LocalCacheResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static bool TryGetDefaultLocalCacheRoot(GVFSEnlistment enlistment, out st
return true;
}

return GVFSPlatform.Instance.TryGetDefaultLocalCacheRoot(enlistment.EnlistmentRoot, out localCacheRoot, out localCacheRootError);
return GVFSPlatform.Instance.TryGetDefaultLocalCacheRoot(enlistment.PrimaryEnlistmentRoot, out localCacheRoot, out localCacheRootError);
}

public bool TryGetLocalCacheKeyFromLocalConfigOrRemoteCacheServers(
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/Maintenance/GitMaintenanceStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static bool EnlistmentRootReady(GVFSContext context)
// a "Device is not ready" error.
try
{
return context.FileSystem.DirectoryExists(context.Enlistment.EnlistmentRoot)
return context.FileSystem.DirectoryExists(context.Enlistment.WorkingDirectoryRoot)
&& context.FileSystem.DirectoryExists(context.Enlistment.GitObjectsRoot);
}
catch (IOException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,101 @@ public void WorktreeOutsideEnlistmentTree()
}
}

[TestCase]
public void WorktreeUsesPerWorktreePlaceholderDatabase()
Comment thread
tyrielv marked this conversation as resolved.
{
// Two commits where test4.txt has different content
const string CommitA = "5d7a7d4db1734fb468a4094469ec58d26301b59d";
const string CommitB = "fec239ea12de1eda6ae5329d4f345784d5b61ff9";
string testFileRelativePath = Path.Combine(
"Test_EPF_UpdatePlaceholderTests",
"LockToPreventUpdateAndDelete",
"test4.txt");
const string ContentAtCommitA = "TestFileLockToPreventUpdateAndDelete4 \r\n";
const string ContentAtCommitB = "Commit2LockToPreventUpdateAndDelete4 \r\n";

string suffix = Guid.NewGuid().ToString("N").Substring(0, 8);
string tempDir = Path.Combine(Path.GetTempPath(), $"gvfs-db-test-{suffix}");
string worktreePath = Path.Combine(tempDir, "wt");
string branchName = $"db-test-branch-{suffix}";

try
{
Directory.CreateDirectory(tempDir);

// 1. Checkout commitB in the primary and read the file to
// create a placeholder with version B content.
GitHelpers.InvokeGitAgainstGVFSRepo(
this.Enlistment.RepoRoot, $"checkout {CommitB}")
.ExitCode.ShouldEqual(0, "checkout commitB in primary failed");

string primaryFilePath = Path.Combine(this.Enlistment.RepoRoot, testFileRelativePath);
File.ReadAllText(primaryFilePath).ShouldEqual(ContentAtCommitB,
"Primary should have version B content");

// 2. Create a worktree at commitA and read the same file.
// Without the fix, the worktree mount writes the placeholder
// entry (SHA_A) to the primary's DB, overwriting SHA_B.
ProcessResult addResult = GitHelpers.InvokeGitAgainstGVFSRepo(
this.Enlistment.RepoRoot,
$"worktree add -b {branchName} \"{worktreePath}\" {CommitA}");
addResult.ExitCode.ShouldEqual(0,
$"worktree add failed: {addResult.Errors}");

this.AssertWorktreeMounted(worktreePath, "db-test worktree");

string worktreeFilePath = Path.Combine(worktreePath, testFileRelativePath);
File.ReadAllText(worktreeFilePath).ShouldEqual(ContentAtCommitA,
"Worktree should have version A content");

// 3. Checkout commitA in the primary. UpdatePlaceholders reads
// the placeholder DB to find files that need updating.
// With a contaminated DB (SHA_A from worktree), the primary's
// placeholder (on-disk SHA_B) looks up-to-date (DB says SHA_A,
// index wants SHA_A — match) and the update is skipped.
// The file retains stale commitB content.
GitHelpers.InvokeGitAgainstGVFSRepo(
this.Enlistment.RepoRoot, $"checkout {CommitA}")
.ExitCode.ShouldEqual(0, "checkout commitA in primary failed");

string contentAfterCheckout = File.ReadAllText(primaryFilePath);
contentAfterCheckout.ShouldEqual(ContentAtCommitA,
$"After checkout to commitA, primary should have version A content.\n" +
$"Got version B content instead — the worktree mount contaminated\n" +
$"the primary's placeholder DB, causing UpdatePlaceholders to skip\n" +
$"the update because the DB SHA matched the index SHA.");

// 4. Verify the per-worktree placeholder DB exists (isolation check)
GVFSEnlistment.WorktreeInfo wtInfo = GVFSEnlistment.TryGetWorktreeInfo(worktreePath);
Assert.IsNotNull(wtInfo, "Should be able to resolve worktree info");
string worktreeDbPath = Path.Combine(
wtInfo.WorktreeGitDir, ".gvfs", "databases", "VFSForGit.sqlite");

bool dbExists = false;
for (int i = 0; i < 20; i++)
{
if (File.Exists(worktreeDbPath))
{
dbExists = true;
break;
}

System.Threading.Thread.Sleep(500);
}

Assert.IsTrue(dbExists,
$"Per-worktree VFSForGit.sqlite should exist at {worktreeDbPath}");
}
finally
{
this.ForceCleanupWorktree(worktreePath, branchName);
if (Directory.Exists(tempDir))
{
try { Directory.Delete(tempDir, recursive: true); } catch { }
}
}
}

private void InitWorktreeArrays(int count, out string[] paths, out string[] branches)
{
paths = new string[count];
Expand Down
Loading
Loading