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

Commit dd771c1

Browse files
Merge branch 'master' into add-dev-oauth-key
2 parents 11091bc + f0f12c6 commit dd771c1

File tree

6 files changed

+86
-9
lines changed

6 files changed

+86
-9
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/GitHub.Api.csproj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,25 @@
295295
Other similar extension points exist, see Microsoft.Common.targets.
296296
<Target Name="BeforeBuild">
297297
</Target>
298+
-->
298299
<Target Name="AfterBuild">
300+
<Copy
301+
SourceFiles="PlatformResources\linux\git-lfs.zip;PlatformResources\linux\git-lfs.json"
302+
DestinationFolder="$(SolutionDir)\src\UnityExtension\Assets\Editor\GitHub.Unity\PlatformResources\linux"
303+
SkipUnchangedFiles="true"
304+
/>
305+
306+
<Copy
307+
SourceFiles="PlatformResources\mac\git-lfs.zip;PlatformResources\mac\git-lfs.json"
308+
DestinationFolder="$(SolutionDir)\src\UnityExtension\Assets\Editor\GitHub.Unity\PlatformResources\mac"
309+
SkipUnchangedFiles="true"
310+
/>
311+
312+
<Copy
313+
SourceFiles="PlatformResources\windows\git.zip;PlatformResources\windows\git.json;PlatformResources\windows\git-lfs.zip;PlatformResources\windows\git-lfs.json"
314+
DestinationFolder="$(SolutionDir)\src\UnityExtension\Assets\Editor\GitHub.Unity\PlatformResources\windows"
315+
SkipUnchangedFiles="true"
316+
/>
299317
</Target>
300-
-->
301318
<Import Project="..\..\common\build.targets" />
302319
</Project>

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
5555
}
5656

5757
state = VerifyZipFiles(state);
58+
// on developer builds, prefer local zips over downloading
59+
#if DEVELOPER_BUILD
60+
state = GrabZipFromResourcesIfNeeded(state);
61+
state = GetZipsIfNeeded(state);
62+
#else
5863
state = GetZipsIfNeeded(state);
5964
state = GrabZipFromResourcesIfNeeded(state);
65+
#endif
6066
state = ExtractGit(state);
6167

6268
// if installing from zip failed (internet down maybe?), try to find a usable system git

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);

src/UnityExtension/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
*.csproj
22
UnityPackageManager
33
JetBrains
4-
UnityExtension.sln
4+
UnityExtension.sln
5+
Assets/**/*.zip
6+
Assets/**/*.md5
7+
Assets/**/*.json

0 commit comments

Comments
 (0)