Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 362ec6c

Browse files
Merge branch 'master' into use-local-zips-when-developing
2 parents 3b1e908 + 0e1bdff commit 362ec6c

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

src/GitHub.Api/Events/RepositoryWatcher.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class RepositoryWatcher : IRepositoryWatcher
3030
private readonly NPath[] ignoredPaths;
3131
private readonly ManualResetEventSlim pauseEvent;
3232
private NativeInterface nativeInterface;
33+
private NativeInterface worktreeNativeInterface;
3334
private bool running;
3435
private int lastCountOfProcessedEvents = 0;
3536
private bool processingEvents;
@@ -64,6 +65,11 @@ public void Initialize()
6465
try
6566
{
6667
nativeInterface = new NativeInterface(pathsRepositoryPath);
68+
69+
if (paths.IsWorktree)
70+
{
71+
worktreeNativeInterface = new NativeInterface(paths.WorktreeDotGitPath);
72+
}
6773
}
6874
catch (Exception ex)
6975
{
@@ -80,6 +86,18 @@ public void Start()
8086
}
8187

8288
Logger.Trace("Watching Path: \"{0}\"", paths.RepositoryPath.ToString());
89+
90+
if (paths.IsWorktree)
91+
{
92+
if (worktreeNativeInterface == null)
93+
{
94+
Logger.Warning("Worktree NativeInterface is null");
95+
throw new InvalidOperationException("Worktree NativeInterface is null");
96+
}
97+
98+
Logger.Trace("Watching Additional Path for Worktree: \"{0}\"", paths.WorktreeDotGitPath);
99+
}
100+
83101
running = true;
84102
pauseEvent.Reset();
85103
Task.Factory.StartNew(WatcherLoop, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
@@ -131,6 +149,15 @@ public int CheckAndProcessEvents()
131149
processedEventCount = ProcessEvents(fileEvents);
132150
}
133151

152+
if (worktreeNativeInterface != null)
153+
{
154+
fileEvents = worktreeNativeInterface.GetEvents();
155+
if (fileEvents.Length > 0)
156+
{
157+
processedEventCount = processedEventCount + ProcessEvents(fileEvents);
158+
}
159+
}
160+
134161
lastCountOfProcessedEvents = processedEventCount;
135162
processingEvents = false;
136163
signalProcessingEventsDone.Set();
@@ -158,7 +185,7 @@ private int ProcessEvents(Event[] fileEvents)
158185
var fileA = eventDirectory.Combine(fileEvent.FileA);
159186

160187
// handling events in .git/*
161-
if (fileA.IsChildOf(paths.DotGitPath))
188+
if (fileA.IsChildOf(paths.DotGitPath) || (paths.WorktreeDotGitPath.IsInitialized && fileA.IsChildOf(paths.WorktreeDotGitPath)))
162189
{
163190
if (!events.Contains(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
164191
{

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,57 @@ interface IRepositoryPathConfiguration
6060
NPath DotGitIndex { get; }
6161
NPath DotGitHead { get; }
6262
NPath DotGitConfig { get; }
63+
NPath WorktreeDotGitPath { get; }
64+
bool IsWorktree { get; }
6365
}
6466

6567
class RepositoryPathConfiguration : IRepositoryPathConfiguration
6668
{
6769
public RepositoryPathConfiguration(NPath repositoryPath)
6870
{
6971
RepositoryPath = repositoryPath;
72+
WorktreeDotGitPath = NPath.Default;
7073

7174
DotGitPath = repositoryPath.Combine(".git");
75+
NPath commonPath;
7276
if (DotGitPath.FileExists())
7377
{
7478
DotGitPath =
7579
DotGitPath.ReadAllLines()
7680
.Where(x => x.StartsWith("gitdir:"))
7781
.Select(x => x.Substring(7).Trim().ToNPath())
7882
.First();
83+
if (DotGitPath.Combine("commondir").FileExists())
84+
{
85+
commonPath = DotGitPath.Combine("commondir").ReadAllLines()
86+
.Select(x => x.Trim().ToNPath())
87+
.First();
88+
commonPath = DotGitPath.Combine(commonPath);
89+
90+
IsWorktree = true;
91+
WorktreeDotGitPath = commonPath;
92+
}
93+
else
94+
{
95+
commonPath = DotGitPath;
96+
}
97+
}
98+
else
99+
{
100+
commonPath = DotGitPath;
79101
}
80102

81-
BranchesPath = DotGitPath.Combine("refs", "heads");
82-
RemotesPath = DotGitPath.Combine("refs", "remotes");
103+
BranchesPath = commonPath.Combine("refs", "heads");
104+
RemotesPath = commonPath.Combine("refs", "remotes");
83105
DotGitIndex = DotGitPath.Combine("index");
84106
DotGitHead = DotGitPath.Combine("HEAD");
85-
DotGitConfig = DotGitPath.Combine("config");
107+
DotGitConfig = commonPath.Combine("config");
86108
DotGitCommitEditMsg = DotGitPath.Combine("COMMIT_EDITMSG");
87109
}
88110

111+
public bool IsWorktree { get; }
89112
public NPath RepositoryPath { get; }
113+
public NPath WorktreeDotGitPath { get; }
90114
public NPath DotGitPath { get; }
91115
public NPath BranchesPath { get; }
92116
public NPath RemotesPath { get; }

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public void InitializeRepository(NPath? repositoryPath = null)
8989

9090
expectedRepositoryPath = repositoryPath != null ? repositoryPath.Value : UnityProjectPath;
9191

92-
if (!expectedRepositoryPath.DirectoryExists(".git"))
92+
if (!expectedRepositoryPath.Exists(".git"))
9393
{
94-
NPath reporoot = UnityProjectPath.RecursiveParents.FirstOrDefault(d => d.DirectoryExists(".git"));
94+
NPath reporoot = UnityProjectPath.RecursiveParents.FirstOrDefault(d => d.Exists(".git"));
9595
if (reporoot.IsInitialized)
9696
expectedRepositoryPath = reporoot;
9797
}
@@ -102,7 +102,7 @@ public void InitializeRepository(NPath? repositoryPath = null)
102102
}
103103

104104
FileSystem.SetCurrentDirectory(expectedRepositoryPath);
105-
if (expectedRepositoryPath.DirectoryExists(".git"))
105+
if (expectedRepositoryPath.Exists(".git"))
106106
{
107107
RepositoryPath = expectedRepositoryPath;
108108
Repository = new Repository(RepositoryPath, CacheContainer);

0 commit comments

Comments
 (0)