Forge
csharp8e44aa49
1using GitMcp.Core;
2
3namespace GitMcp.Tests;
4
5public sealed class GitWorkTreeTests
6{
7 [Fact]
8 public void GetRepoRoot_accepts_dot_git_directory()
9 {
10 var d = NewTempDir();
11 Directory.CreateDirectory(Path.Combine(d, ".git"));
12 try
13 {
14 Assert.Equal(Path.GetFullPath(d), GitWorkTree.GetRepoRoot(d));
15 }
16 finally
17 {
18 Directory.Delete(d, recursive: true);
19 }
20 }
21
22 [Fact]
23 public void GetRepoRoot_accepts_dot_git_file_like_submodule()
24 {
25 var d = NewTempDir();
26 File.WriteAllText(Path.Combine(d, ".git"), "gitdir: ../../../.git/modules/foo\n");
27 try
28 {
29 Assert.Equal(Path.GetFullPath(d), GitWorkTree.GetRepoRoot(d));
30 }
31 finally
32 {
33 Directory.Delete(d, recursive: true);
34 }
35 }
36
37 [Fact]
38 public void GetRepoRoot_rejects_plain_directory_without_git()
39 {
40 var d = NewTempDir();
41 try
42 {
43 var ex = Assert.Throws<ArgumentException>(() => GitWorkTree.GetRepoRoot(d));
44 Assert.Contains("Not a git repository", ex.Message, StringComparison.Ordinal);
45 }
46 finally
47 {
48 Directory.Delete(d, recursive: true);
49 }
50 }
51
52 [Fact]
53 public void IsGitWorkTreeRoot_false_for_random_dir()
54 {
55 var d = NewTempDir();
56 try
57 {
58 Assert.False(GitWorkTree.IsGitWorkTreeRoot(d));
59 }
60 finally
61 {
62 Directory.Delete(d, recursive: true);
63 }
64 }
65
66 static string NewTempDir()
67 {
68 var d = Path.Combine(Path.GetTempPath(), "gitmcp-worktree-test-" + Guid.NewGuid().ToString("n"));
69 Directory.CreateDirectory(d);
70 return d;
71 }
72}
73
View only · write via MCP/CIDE