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

Commit 2a3c334

Browse files
committed
Merge fixes/mac-path-variable-more into stanley/0.31-rc
2 parents bef9c04 + ba24c19 commit 2a3c334

File tree

17 files changed

+389
-332
lines changed

17 files changed

+389
-332
lines changed

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;
@@ -179,7 +179,6 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
179179
return;
180180
}
181181

182-
Logger.Trace($"CacheInvalidated {cacheType.ToString()}");
183182
switch (cacheType)
184183
{
185184
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);

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ public GitInstaller(IEnvironment environment, IProcessManager processManager,
3030
public ITask<GitInstallationState> SetupGitIfNeeded()
3131
{
3232
//Logger.Trace("SetupGitIfNeeded");
33-
33+
GitInstallationState installationState = new GitInstallationState();
3434
installationTask = new FuncTask<GitInstallationState, GitInstallationState>(cancellationToken, (success, path) => path)
3535
{ Name = "Git Installation - Complete" };
3636
installationTask.OnStart += thisTask => thisTask.UpdateProgress(0, 100);
3737
installationTask.OnEnd += (thisTask, result, success, exception) => thisTask.UpdateProgress(100, 100);
3838

3939
ITask<GitInstallationState> startTask = null;
40-
GitInstallationState installationState = new GitInstallationState();
4140
if (!environment.IsWindows)
4241
{
4342
var findTask = new FindExecTask("git", cancellationToken)
@@ -72,37 +71,47 @@ public ITask<GitInstallationState> SetupGitIfNeeded()
7271
{
7372
startTask = new FuncTask<GitInstallationState>(cancellationToken, () =>
7473
{
75-
installationState = VerifyGitInstallation();
76-
if (!installationState.GitIsValid && !installationState.GitLfsIsValid)
77-
installationState = GrabZipFromResources(installationState);
78-
else
79-
Logger.Trace("SetupGitIfNeeded: Skipped");
80-
return installationState;
74+
return VerifyPortableGitInstallation();
8175
})
8276
{ Name = "Git Installation - Extract" };
8377
}
8478

79+
startTask = startTask.Then(new FuncTask<GitInstallationState, GitInstallationState>(cancellationToken, (success, installState) =>
80+
{
81+
if (installState.GitIsValid && installState.GitLfsIsValid)
82+
{
83+
return installState;
84+
}
85+
86+
installState = VerifyZipFiles(installState);
87+
installState = GrabZipFromResourcesIfNeeded(installState);
88+
return installState;
89+
})
90+
{ Name = "Git Installation - Validate" }
91+
);
92+
8593
startTask.OnEnd += (thisTask, installState, success, exception) =>
8694
{
87-
if (!installState.GitIsValid && !installState.GitLfsIsValid)
95+
if (installState.GitIsValid && installState.GitLfsIsValid)
8896
{
89-
if (!installState.GitZipExists || !installState.GitLfsZipExists)
90-
thisTask = thisTask.Then(CreateDownloadTask(installState));
91-
thisTask = thisTask.Then(ExtractPortableGit(installState));
97+
Logger.Trace("Skipping git installation");
98+
thisTask.Then(installationTask);
99+
return;
92100
}
93-
thisTask = thisTask.Then(installationTask);
101+
102+
var downloadZipTask = DownloadZipsIfNeeded(installState);
103+
downloadZipTask.OnEnd += ExtractPortableGit;
104+
thisTask.Then(downloadZipTask);
94105
};
95106

96107
return startTask;
97108
}
98109

99-
private GitInstallationState VerifyGitInstallation()
110+
private GitInstallationState VerifyPortableGitInstallation()
100111
{
101112
var state = new GitInstallationState();
102113
var gitExists = installDetails.GitExecutablePath.IsInitialized && installDetails.GitExecutablePath.FileExists();
103114
var gitLfsExists = installDetails.GitLfsExecutablePath.IsInitialized && installDetails.GitLfsExecutablePath.FileExists();
104-
state.GitZipExists = installDetails.GitZipPath.FileExists();
105-
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
106115

107116
if (gitExists)
108117
{
@@ -144,26 +153,44 @@ private GitInstallationState VerifyGitInstallation()
144153
return state;
145154
}
146155

147-
private GitInstallationState GrabZipFromResources(GitInstallationState state)
156+
private GitInstallationState VerifyZipFiles(GitInstallationState state)
157+
{
158+
var md5 = AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", installDetails.ZipPath, environment);
159+
if (!md5.FileExists() || (installDetails.GitZipPath.FileExists() && !Utils.VerifyFileIntegrity(installDetails.GitZipPath, md5)))
160+
{
161+
installDetails.GitZipPath.DeleteIfExists();
162+
}
163+
state.GitZipExists = installDetails.GitZipPath.FileExists();
164+
165+
md5 = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", installDetails.ZipPath, environment);
166+
// check whether the git-lfs zip file exists and is valid
167+
if (!md5.FileExists() || (installDetails.GitLfsZipPath.FileExists() && !Utils.VerifyFileIntegrity(installDetails.GitLfsZipPath, md5)))
168+
{
169+
installDetails.GitLfsZipPath.DeleteIfExists();
170+
}
171+
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
172+
installationTask.UpdateProgress(20, 100);
173+
return state;
174+
}
175+
176+
private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
148177
{
149178
if (!state.GitZipExists)
150179
{
151180
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
152-
AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", installDetails.ZipPath, environment);
153181
}
154182
state.GitZipExists = installDetails.GitZipPath.FileExists();
155183

156184
if (!state.GitLfsZipExists)
157185
{
158186
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
159-
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", installDetails.ZipPath, environment);
160187
}
161188
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
162-
installationTask.UpdateProgress(20, 100);
189+
installationTask.UpdateProgress(30, 100);
163190
return state;
164191
}
165192

166-
private ITask<GitInstallationState> CreateDownloadTask(GitInstallationState state)
193+
private ITask<GitInstallationState> DownloadZipsIfNeeded(GitInstallationState state)
167194
{
168195
var downloader = new Downloader();
169196
downloader.Catch(e => true);
@@ -180,7 +207,8 @@ private ITask<GitInstallationState> CreateDownloadTask(GitInstallationState stat
180207
});
181208
}
182209

183-
private FuncTask<GitInstallationState> ExtractPortableGit(GitInstallationState state)
210+
private void ExtractPortableGit(ITask<GitInstallationState> thisTask,
211+
GitInstallationState state, bool s, Exception exception)
184212
{
185213
ITask<NPath> task = null;
186214
var tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
@@ -252,7 +280,9 @@ private FuncTask<GitInstallationState> ExtractPortableGit(GitInstallationState s
252280
endTask = task.Then(endTask);
253281
}
254282

255-
return endTask;
283+
thisTask
284+
.Then(endTask)
285+
.Then(installationTask);
256286
}
257287

258288
public class GitInstallationState

src/GitHub.Api/Managers/Downloader.cs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class Downloader : FuncListTask<DownloadData>
2929
private readonly List<PairDownloader> downloaders = new List<PairDownloader>();
3030

3131
public Downloader() : base(TaskManager.Instance.Token, RunDownloaders)
32-
{}
32+
{
33+
Name = "Downloader";
34+
}
3335

3436
public void QueueDownload(UriString url, UriString md5Url, NPath targetDirectory)
3537
{
@@ -70,6 +72,7 @@ class PairDownloader
7072
private int finishedTaskCount;
7173
private volatile bool isSuccessful = true;
7274
private volatile Exception exception;
75+
private DownloadData result;
7376

7477
public PairDownloader()
7578
{
@@ -84,15 +87,15 @@ public Task<DownloadData> Run()
8487
foreach (var task in queuedTasks)
8588
task.Start();
8689
if (queuedTasks.Count == 0)
87-
DownloadComplete(null);
90+
DownloadComplete(result);
8891
return aggregateDownloads.Task;
8992
}
9093

9194
public Task<DownloadData> QueueDownload(UriString url, UriString md5Url, NPath targetDirectory)
9295
{
9396
var destinationFile = targetDirectory.Combine(url.Filename);
9497
var destinationMd5 = targetDirectory.Combine(md5Url.Filename);
95-
var result = new DownloadData(url, destinationFile);
98+
result = new DownloadData(url, destinationFile);
9699

97100
Action<ITask<NPath>, NPath, bool, Exception> verifyDownload = (t, res, success, ex) =>
98101
{
@@ -123,31 +126,6 @@ public Task<DownloadData> QueueDownload(UriString url, UriString md5Url, NPath t
123126
var md5Exists = destinationMd5.FileExists();
124127
var fileExists = destinationFile.FileExists();
125128

126-
if (fileExists && md5Exists)
127-
{
128-
var verification = new FuncTask<NPath>(cancellationToken, () => destinationFile);
129-
verification.OnStart += _ => DownloadStart?.Invoke(result);
130-
verification.OnEnd += (t, res, success, ex) =>
131-
{
132-
if (!Utils.VerifyFileIntegrity(destinationFile, destinationMd5))
133-
{
134-
destinationMd5.Delete();
135-
destinationFile.Delete();
136-
var fileDownload = DownloadFile(url, targetDirectory, result, verifyDownload);
137-
queuedTasks.Add(fileDownload);
138-
var md5Download = DownloadFile(md5Url, targetDirectory, result, verifyDownload);
139-
queuedTasks.Add(md5Download);
140-
fileDownload.Start();
141-
md5Download.Start();
142-
}
143-
else
144-
{
145-
DownloadComplete(result);
146-
}
147-
};
148-
queuedTasks.Add(verification);
149-
}
150-
151129
if (!md5Exists)
152130
{
153131
var md5Download = DownloadFile(md5Url, targetDirectory, result, verifyDownload);

src/GitHub.Api/Platform/ProcessEnvironment.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
6565
{
6666
pathEntries.Add(gitExecutableDir.ToString());
6767
}
68+
6869
if (execPath.IsInitialized)
6970
pathEntries.Add(execPath);
7071
pathEntries.Add(binPath);
7172

73+
// we can only set this env var if there is a libexec/git-core. git will bypass internally bundled tools if this env var
74+
// is set, which will break Apple's system git on certain tools (like osx-credentialmanager)
7275
if (execPath.IsInitialized)
7376
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
7477
}
@@ -88,8 +91,11 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSet
8891
//TODO: Remove with Git LFS Locking becomes standard
8992
psi.EnvironmentVariables["GITLFSLOCKSENABLED"] = "1";
9093

91-
psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh";
92-
psi.EnvironmentVariables["TERM"] = "msys";
94+
if (Environment.IsWindows)
95+
{
96+
psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh";
97+
psi.EnvironmentVariables["TERM"] = "msys";
98+
}
9399

94100
var httpProxy = Environment.GetEnvironmentVariable("HTTP_PROXY");
95101
if (!String.IsNullOrEmpty(httpProxy))

0 commit comments

Comments
 (0)