-
Notifications
You must be signed in to change notification settings - Fork 466
fix worktree mounts using primary enlistment's .gvfs paths #1998
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,6 +268,82 @@ public void WorktreeOutsideEnlistmentTree() | |
| } | ||
| } | ||
|
|
||
| [TestCase] | ||
| public void WorktreeUsesPerWorktreePlaceholderDatabase() | ||
| { | ||
| 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. Create worktree outside the enlistment tree | ||
| ProcessResult addResult = GitHelpers.InvokeGitAgainstGVFSRepo( | ||
| this.Enlistment.RepoRoot, | ||
| $"worktree add -b {branchName} \"{worktreePath}\""); | ||
| addResult.ExitCode.ShouldEqual(0, | ||
| $"worktree add failed: {addResult.Errors}"); | ||
|
|
||
| // 2. Verify GVFS mount is running | ||
| this.AssertWorktreeMounted(worktreePath, "db-test worktree"); | ||
|
|
||
| // 3. Resolve the per-worktree .gvfs path through the gitdir chain | ||
| GVFSEnlistment.WorktreeInfo wtInfo = GVFSEnlistment.TryGetWorktreeInfo(worktreePath); | ||
| Assert.IsNotNull(wtInfo, "Should be able to resolve worktree info"); | ||
| string worktreeDotGVFS = Path.Combine(wtInfo.WorktreeGitDir, ".gvfs"); | ||
| string worktreeDbPath = Path.Combine(worktreeDotGVFS, "databases", "VFSForGit.sqlite"); | ||
|
|
||
| // 4. Materialize a file in the worktree by reading it | ||
| string testFilePath = Path.Combine(worktreePath, "Readme.md"); | ||
| File.Exists(testFilePath).ShouldBeTrue("Readme.md should be projected"); | ||
| File.ReadAllText(testFilePath); | ||
|
|
||
| // 5. Wait for background operations to flush placeholder entries | ||
| // The primary mount handles background tasks; give it time to | ||
| // process the worktree's placeholder creation. | ||
| System.Threading.Thread.Sleep(2000); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A thread.sleep(2000) could create a flaky test/output, is there a more deterministic approach we could use here? |
||
|
|
||
| // 6. Verify the per-worktree placeholder DB has entries | ||
| File.Exists(worktreeDbPath).ShouldBeTrue( | ||
| $"Per-worktree VFSForGit.sqlite should exist at {worktreeDbPath}"); | ||
|
|
||
| string worktreePlaceholders = GVFSHelpers.GetAllSQLitePlaceholdersAsString(worktreeDbPath); | ||
| Assert.IsTrue( | ||
| worktreePlaceholders.Contains("Readme.md"), | ||
| $"Per-worktree placeholder DB should contain Readme.md entry.\n" + | ||
| $"DB path: {worktreeDbPath}\n" + | ||
| $"DB contents:\n{worktreePlaceholders}"); | ||
|
|
||
| // 7. Verify the primary's placeholder DB does NOT contain a | ||
| // duplicate entry from worktree materialization. The primary | ||
| // DB tracks the primary enlistment's placeholders only. | ||
| string primaryDbPath = Path.Combine( | ||
| this.Enlistment.DotGVFSRoot, "databases", "VFSForGit.sqlite"); | ||
| string primaryPlaceholders = GVFSHelpers.GetAllSQLitePlaceholdersAsString(primaryDbPath); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test computes primaryPlaceholders but never asserts on it; the comment two lines above promises an isolation check that the test does not perform. |
||
|
|
||
| // Both DBs will have Readme.md since it exists in both worktrees, | ||
| // but the worktree DB must have its own non-empty set of entries | ||
| // (not be 0 bytes or an empty table). | ||
| long worktreeDbSize = new FileInfo(worktreeDbPath).Length; | ||
| Assert.Greater(worktreeDbSize, 0, | ||
| "Per-worktree placeholder DB should not be 0 bytes"); | ||
|
|
||
| // 8. Cleanup is handled in the finally block — worktree remove | ||
| // can fail transiently due to handle release timing after unmount. | ||
| } | ||
| 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]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new test verifies a placeholder row exists, but doesn't capture stale content after 'git reset --hard' in a worktree.