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

Commit 0f3bc38

Browse files
authored
Merge pull request #672 from github-for-unity/fixes/mac-path-variable-more
Fix a bunch of stuff in the git installation process
2 parents 5562b63 + ba24c19 commit 0f3bc38

27 files changed

+754
-465
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void Run(bool firstRun)
7474
}
7575
};
7676

77-
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken,
78-
(_, path) => InitializeEnvironment(path))
77+
var initEnvironmentTask = new ActionTask<GitInstaller.GitInstallationState>(CancellationToken,
78+
(_, state) => InitializeEnvironment(state))
7979
{ Affinity = TaskAffinity.UI };
8080

8181
isBusy = true;
@@ -227,20 +227,22 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
227227
/// </summary>
228228
/// <param name="gitExecutablePath"></param>
229229
/// <param name="octorunScriptPath"></param>
230-
private void InitializeEnvironment(NPath gitExecutablePath)
230+
private void InitializeEnvironment(GitInstaller.GitInstallationState installationState)
231231
{
232232
isBusy = false;
233233
SetupMetrics();
234234

235-
if (!gitExecutablePath.IsInitialized)
235+
if (!installationState.GitIsValid)
236236
{
237237
return;
238238
}
239-
239+
240240
var gitInstallDetails = new GitInstaller.GitInstallDetails(Environment.UserCachePath, Environment.IsWindows);
241-
var isCustomGitExec = gitExecutablePath != gitInstallDetails.GitExecutablePath;
241+
var isCustomGitExec = installationState.GitExecutablePath != gitInstallDetails.GitExecutablePath;
242+
243+
Environment.GitExecutablePath = installationState.GitExecutablePath;
244+
Environment.GitLfsExecutablePath = installationState.GitLfsExecutablePath;
242245

243-
Environment.GitExecutablePath = gitExecutablePath;
244246
Environment.IsCustomGitExecutable = isCustomGitExec;
245247
Environment.User.Initialize(GitClient);
246248

src/GitHub.Api/Cache/CacheContainer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ public void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEven
6060

6161
private void OnCacheUpdated(CacheType cacheType, DateTimeOffset datetime)
6262
{
63-
Logger.Trace("OnCacheUpdated cacheType:{0} datetime:{1}", cacheType, datetime);
6463
CacheUpdated.SafeInvoke(cacheType, datetime);
6564
}
6665

6766
private void OnCacheInvalidated(CacheType cacheType)
6867
{
69-
Logger.Trace("OnCacheInvalidated cacheType:{0}", cacheType);
7068
CacheInvalidated.SafeInvoke(cacheType);
7169
}
7270

src/GitHub.Api/Git/GitConfig.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,20 @@ public struct ConfigBranch
7979

8080
public string name;
8181
public ConfigRemote remote;
82+
public string trackingBranch;
8283

8384
public ConfigBranch(string name)
8485
{
8586
this.name = name;
87+
this.trackingBranch = null;
8688
remote = ConfigRemote.Default;
8789
}
8890

89-
public ConfigBranch(string name, ConfigRemote? remote)
91+
public ConfigBranch(string name, ConfigRemote? remote, string trackingBranch)
9092
{
9193
this.name = name;
9294
this.remote = remote ?? ConfigRemote.Default;
95+
this.trackingBranch = trackingBranch != null && trackingBranch.StartsWith("refs/heads") ? trackingBranch.Substring("refs/heads".Length + 1) : null;
9396
}
9497

9598
public override int GetHashCode()
@@ -137,6 +140,7 @@ public bool Equals(ConfigBranch other)
137140
public bool IsTracking => Remote.HasValue;
138141

139142
public string Name => name;
143+
public string TrackingBranch => trackingBranch;
140144

141145
public ConfigRemote? Remote => Equals(remote, ConfigRemote.Default) ? (ConfigRemote?) null : remote;
142146

@@ -189,7 +193,7 @@ public IEnumerable<ConfigBranch> GetBranches()
189193
return groups
190194
.Where(x => x.Key == "branch")
191195
.SelectMany(x => x.Value)
192-
.Select(x => new ConfigBranch(x.Key, GetRemote(x.Value.TryGetString("remote"))));
196+
.Select(x => new ConfigBranch(x.Key, GetRemote(x.Value.TryGetString("remote")), x.Value.TryGetString("merge")));
193197
}
194198

195199
public IEnumerable<ConfigRemote> GetRemotes()
@@ -217,7 +221,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
217221
.Where(x => x.Key == "branch")
218222
.SelectMany(x => x.Value)
219223
.Where(x => x.Key == branch)
220-
.Select(x => new ConfigBranch(x.Key,GetRemote(x.Value.TryGetString("remote"))) as ConfigBranch?)
224+
.Select(x => new ConfigBranch(x.Key, GetRemote(x.Value.TryGetString("remote")), x.Value.TryGetString("merge")) as ConfigBranch?)
221225
.FirstOrDefault();
222226
}
223227

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GitHub.Unity
88
/// </summary>
99
public interface IRepository : IEquatable<IRepository>, IDisposable
1010
{
11-
void Initialize(IRepositoryManager repositoryManager, ITaskManager taskManager);
11+
void Initialize(IRepositoryManager theRepositoryManager, ITaskManager theTaskManager);
1212
void Start();
1313

1414
ITask CommitAllFiles(string message, string body);

src/GitHub.Api/Git/Repository.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public Repository(NPath localPath, ICacheContainer container)
7070
};
7171
}
7272

73-
public void Initialize(IRepositoryManager repositoryManager, ITaskManager taskManager)
73+
public void Initialize(IRepositoryManager theRepositoryManager, ITaskManager theTaskManager)
7474
{
7575
//Logger.Trace("Initialize");
76-
Guard.ArgumentNotNull(repositoryManager, nameof(repositoryManager));
77-
Guard.ArgumentNotNull(taskManager, nameof(taskManager));
76+
Guard.ArgumentNotNull(theRepositoryManager, nameof(theRepositoryManager));
77+
Guard.ArgumentNotNull(theTaskManager, nameof(theTaskManager));
7878

79-
this.taskManager = taskManager;
80-
this.repositoryManager = repositoryManager;
79+
this.taskManager = theTaskManager;
80+
this.repositoryManager = theRepositoryManager;
8181
this.repositoryManager.CurrentBranchUpdated += RepositoryManagerOnCurrentBranchUpdated;
8282
this.repositoryManager.GitStatusUpdated += RepositoryManagerOnGitStatusUpdated;
8383
this.repositoryManager.GitAheadBehindStatusUpdated += RepositoryManagerOnGitAheadBehindStatusUpdated;
@@ -176,7 +176,6 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
176176
return;
177177
}
178178

179-
Logger.Trace($"CacheInvalidated {cacheType.ToString()}");
180179
switch (cacheType)
181180
{
182181
case CacheType.Branches:

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void UpdateGitAheadBehindStatus()
348348
if (configBranch.HasValue && configBranch.Value.Remote.HasValue)
349349
{
350350
var name = configBranch.Value.Name;
351-
var trackingName = configBranch.Value.IsTracking ? configBranch.Value.Remote.Value.Name + "/" + name : "[None]";
351+
var trackingName = configBranch.Value.IsTracking ? configBranch.Value.Remote.Value.Name + "/" + configBranch.Value.TrackingBranch : "[None]";
352352

353353
var task = GitClient.AheadBehindStatus(name, trackingName)
354354
.Then((success, status) =>
@@ -491,6 +491,10 @@ private void WatcherOnLocalBranchesChanged()
491491
{
492492
Logger.Trace("WatcherOnLocalBranchesChanged");
493493
DataNeedsRefreshing?.Invoke(CacheType.Branches);
494+
// the watcher should tell us what branch has changed so we can fire this only
495+
// when the active branch has changed
496+
DataNeedsRefreshing?.Invoke(CacheType.GitLog);
497+
DataNeedsRefreshing?.Invoke(CacheType.GitAheadBehind);
494498
}
495499

496500
private void WatcherOnRepositoryCommitted()
@@ -520,6 +524,7 @@ private void WatcherOnHeadChanged()
520524
Logger.Trace("WatcherOnHeadChanged");
521525
DataNeedsRefreshing?.Invoke(CacheType.RepositoryInfo);
522526
DataNeedsRefreshing?.Invoke(CacheType.GitLog);
527+
DataNeedsRefreshing?.Invoke(CacheType.GitAheadBehind);
523528
}
524529

525530
private void WatcherOnIndexChanged()
@@ -577,7 +582,7 @@ private void UpdateRemoteBranches()
577582
.Select(x => x.RelativeTo(basedir))
578583
.Select(x => x.ToString(SlashMode.Forward)))
579584
{
580-
branchList.Add(branch, new ConfigBranch(branch, remotes[remote]));
585+
branchList.Add(branch, new ConfigBranch(branch, remotes[remote], null));
581586
}
582587

583588
remoteBranches.Add(remote, branchList);

0 commit comments

Comments
 (0)