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

Commit 0620350

Browse files
Merge branch 'enhancements/git-setup-download' into enhancements/window-loading-view
2 parents 42e11a6 + 4682d1b commit 0620350

22 files changed

+1078
-514
lines changed

GitHub.Unity.sln.DotSettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
</TypePattern>
336336
&lt;/Patterns&gt;</s:String>
337337
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
338-
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MD/@EntryIndexedValue">ME</s:String>
338+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MD/@EntryIndexedValue">MD</s:String>
339339
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSH/@EntryIndexedValue">SSH</s:String>
340340
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
341341
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 GitHub
3+
Copyright (c) 2016-2018 GitHub
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 54 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -39,103 +39,81 @@ protected void Initialize()
3939
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4040
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4141
Platform.Initialize(ProcessManager, TaskManager);
42-
ITaskManager taskManager = TaskManager;
43-
GitClient = new GitClient(Environment, ProcessManager, taskManager.Token);
42+
GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token);
4443
SetupMetrics();
4544
}
4645

4746
public void Run(bool firstRun)
4847
{
4948
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
5049

51-
SetupGit()
52-
.Then(RestartRepository)
53-
.ThenInUI(InitializeUI)
54-
.Start();
55-
}
50+
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
51+
.ThenInUI(InitializeUI);
5652

57-
private ITask SetupGit()
58-
{
59-
return BuildDetermineGitPathTask()
60-
.Then((b, path) => {
61-
Logger.Trace("Setting GitExecutablePath: {0}", path);
62-
Environment.GitExecutablePath = path;
63-
})
64-
.Then(() => {
65-
if (Environment.GitExecutablePath == null)
53+
//GitClient.GetConfig cannot be called until there is a git path set so it is wrapped in an ActionTask
54+
var windowsCredentialSetup = new ActionTask(CancellationToken, () => {
55+
GitClient.GetConfig("credential.helper", GitConfigSource.Global).Then((b, credentialHelper) => {
56+
if (!string.IsNullOrEmpty(credentialHelper))
6657
{
67-
if (Environment.IsWindows)
68-
{
69-
GitClient.GetConfig("credential.helper", GitConfigSource.Global).Then(
70-
(b, credentialHelper) => {
71-
if (!string.IsNullOrEmpty(credentialHelper))
72-
{
73-
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
74-
}
75-
else
76-
{
77-
Logger.Warning(
78-
"No Windows CredentialHeloper found: Setting to wincred");
79-
80-
GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).Start().Wait();
81-
}
82-
});
83-
}
58+
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
59+
afterGitSetup.Start();
8460
}
85-
})
86-
.ThenInUI(() => {
87-
Environment.User.Initialize(GitClient);
88-
});
89-
}
61+
else
62+
{
63+
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
9064

91-
private TaskBase<NPath> BuildDetermineGitPathTask()
92-
{
93-
TaskBase<NPath> determinePath = new FuncTask<NPath>(CancellationToken, () => {
94-
if (Environment.GitExecutablePath != null)
65+
GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
66+
.Then(() => { afterGitSetup.Start(); }).Start();
67+
}
68+
}).Start();
69+
});
70+
71+
var afterPathDetermined = new ActionTask<NPath>(CancellationToken, (b, path) => {
72+
Logger.Trace("Setting Environment git path: {0}", path);
73+
Environment.GitExecutablePath = path;
74+
}).ThenInUI(() => {
75+
Environment.User.Initialize(GitClient);
76+
77+
if (Environment.IsWindows)
9578
{
96-
return Environment.GitExecutablePath;
79+
windowsCredentialSetup.Start();
9780
}
98-
99-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
100-
if (gitExecutablePath != null && gitExecutablePath.FileExists())
81+
else
10182
{
102-
Logger.Trace("Using git install path from settings");
103-
return gitExecutablePath;
83+
afterGitSetup.Start();
10484
}
105-
106-
return null;
10785
});
10886

109-
var environmentIsWindows = Environment.IsWindows;
110-
if (environmentIsWindows)
111-
{
112-
var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
113-
var installDetails = new PortableGitInstallDetails(applicationDataPath, true);
114-
var installTask = new PortableGitInstallTask(CancellationToken, Environment, installDetails);
115-
116-
determinePath = determinePath.Then(new ShortCircuitTask<NPath>(CancellationToken, installTask));
117-
}
118-
119-
if (!environmentIsWindows)
120-
{
121-
determinePath = determinePath.Then(new ShortCircuitTask<NPath>(CancellationToken, () => {
122-
var p = new NPath("/usr/local/bin/git");
87+
var findExecTask = new FindExecTask("git", CancellationToken)
88+
.Finally((b, ex, path) => {
89+
if (b && path != null)
90+
{
91+
Logger.Trace("FindExecTask Success: {0}", path);
12392

124-
if (p.FileExists())
93+
new FuncTask<NPath>(CancellationToken, () => path)
94+
.Then(afterPathDetermined)
95+
.Start();
96+
}
97+
else
12598
{
126-
return p;
99+
Logger.Warning("FindExecTask Failure");
100+
Logger.Error("Git not found");
127101
}
102+
});
128103

129-
return null;
130-
}));
131-
132-
var findExecTask = new FindExecTask("git", CancellationToken);
133-
findExecTask.Configure(ProcessManager);
134-
135-
determinePath = determinePath.Then(new ShortCircuitTask<NPath>(CancellationToken, findExecTask));
136-
}
137-
138-
return determinePath;
104+
var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
105+
var installDetails = new GitInstallDetails(applicationDataPath, true);
106+
107+
var gitInstaller = new GitInstaller(Environment, CancellationToken, installDetails);
108+
gitInstaller.SetupGitIfNeeded(new ActionTask<NPath>(CancellationToken, (b, path) => {
109+
Logger.Trace("GitInstaller Success: {0}", path);
110+
new FuncTask<NPath>(CancellationToken, () => path)
111+
.Then(afterPathDetermined)
112+
.Start();
113+
}), new ActionTask(CancellationToken, () => {
114+
Logger.Warning("GitInstaller Failure");
115+
findExecTask.Start();
116+
}) );
139117
}
140118

141119
public ITask InitializeRepository()

src/GitHub.Api/Extensions/FileSystemExtensions.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ namespace GitHub.Unity
88
{
99
static class FileSystemExtensions
1010
{
11-
public static string CalculateMD5(this IFileSystem fileSystem, string path)
12-
{
13-
if (fileSystem.DirectoryExists(path))
14-
{
15-
return fileSystem.CalculateFolderMD5(path);
16-
}
17-
18-
if (fileSystem.FileExists(path))
19-
{
20-
return fileSystem.CalculateFileMD5(path);
21-
}
22-
23-
throw new ArgumentException($@"Path does not exist: ""{path}""");
24-
}
25-
2611
public static string CalculateFileMD5(this IFileSystem fileSystem, string file)
2712
{
2813
byte[] computeHash;

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@
117117
<Compile Include="Application\ApplicationManagerBase.cs" />
118118
<Compile Include="Helpers\Constants.cs" />
119119
<Compile Include="Helpers\Validation.cs" />
120-
<Compile Include="Installer\PortableGitInstallTask.cs" />
121-
<Compile Include="Installer\ShortCircuitTask.cs" />
120+
<Compile Include="Installer\GitInstaller.cs" />
122121
<Compile Include="Installer\UnzipTask.cs" />
123122
<Compile Include="OutputProcessors\GitAheadBehindStatusOutputProcessor.cs" />
124123
<Compile Include="OutputProcessors\LfsVersionOutputProcessor.cs" />
@@ -142,6 +141,7 @@
142141
<Compile Include="Tasks\BaseOutputProcessor.cs" />
143142
<Compile Include="Tasks\ConcurrentExclusiveInterleave.cs" />
144143
<Compile Include="Tasks\ConfigOutputProcessor.cs" />
144+
<Compile Include="Tasks\DownloadTask.cs" />
145145
<Compile Include="Tasks\ITaskManager.cs" />
146146
<Compile Include="Tasks\ProcessTask.cs" />
147147
<Compile Include="Tasks\TaskBase.cs" />

src/GitHub.Api/IO/FileSystem.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public bool FileExists(string filename)
3434
return File.Exists(filename);
3535
}
3636

37+
public long FileLength(string path)
38+
{
39+
var fileInfo = new FileInfo(path);
40+
return fileInfo.Length;
41+
}
42+
3743
public IEnumerable<string> GetDirectories(string path)
3844
{
3945
return Directory.GetDirectories(path);
@@ -206,5 +212,10 @@ public Stream OpenRead(string path)
206212
{
207213
return File.OpenRead(path);
208214
}
215+
216+
public Stream OpenWrite(string path, FileMode mode)
217+
{
218+
return new FileStream(path, mode);
219+
}
209220
}
210221
}

src/GitHub.Api/IO/IFileSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace GitHub.Unity
77
public interface IFileSystem
88
{
99
bool FileExists(string path);
10+
long FileLength(string path);
1011
string Combine(string path1, string path2);
1112
string Combine(string path1, string path2, string path3);
1213
string GetFullPath(string path);
@@ -38,6 +39,7 @@ public interface IFileSystem
3839
string ReadAllText(string path);
3940
string ReadAllText(string path, Encoding encoding);
4041
Stream OpenRead(string path);
42+
Stream OpenWrite(string path, FileMode mode);
4143
string[] ReadAllLines(string path);
4244
char DirectorySeparatorChar { get; }
4345
bool ExistingPathIsDirectory(string path);

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,12 @@ public NPath WriteAllText(string contents, Encoding encoding)
907907
return this;
908908
}
909909

910+
public byte[] ReadAllBytes()
911+
{
912+
ThrowIfRelative();
913+
return FileSystem.ReadAllBytes(ToString());
914+
}
915+
910916
public string ReadAllText()
911917
{
912918
ThrowIfRelative();

0 commit comments

Comments
 (0)