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

Commit 5d89039

Browse files
committed
Merge enhancements/git-install-validation into enhancements/git-path-view
2 parents 358e42a + 34d4b0b commit 5d89039

File tree

16 files changed

+167
-140
lines changed

16 files changed

+167
-140
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ private async Task SetupGit()
6464
if (Environment.IsWindows)
6565
{
6666
var credentialHelper = await GitClient.GetConfig("credential.helper", GitConfigSource.Global).StartAwait();
67-
if (string.IsNullOrEmpty(credentialHelper))
67+
68+
if (!string.IsNullOrEmpty(credentialHelper))
69+
{
70+
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
71+
}
72+
else
6873
{
74+
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
75+
6976
await GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).StartAwait();
7077
}
7178
}

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ public async Task<IKeychainAdapter> Load(UriString host)
6464
logger.Warning("Cannot load host from Credential Manager; removing from cache");
6565
await Clear(host, false);
6666
}
67-
else if (keychainItem.Username != cachedConnection.Username)
68-
{
69-
logger.Warning("Item loaded from credential manager does not match connection cache ; removing from cache");
70-
await Clear(host, false);
71-
}
7267
else
7368
{
74-
logger.Trace($@"Loaded from Credential Manager Host:""{keychainItem.Host}"" Username:""{keychainItem.Username}""");
69+
if (keychainItem.Username != cachedConnection.Username)
70+
{
71+
logger.Warning("Keychain Username: {0} does not match; Hopefully it works", keychainItem.Username);
72+
}
73+
74+
logger.Trace("Loaded from Credential Manager Host:\"{0}\" Username:\"{1}\"", keychainItem.Host, keychainItem.Username);
75+
7576
keychainAdapter.Set(keychainItem);
7677
}
7778

src/GitHub.Api/Git/GitClient.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,30 @@ public async Task<NPath> FindGitInstallation()
107107
if (!String.IsNullOrEmpty(environment.GitExecutablePath))
108108
return environment.GitExecutablePath;
109109

110-
var path = await LookForPortableGit();
110+
NPath path = null;
111+
112+
if (environment.IsWindows)
113+
path = await LookForPortableGit();
114+
111115
if (path == null)
112116
path = await LookForSystemGit();
113117

114-
Logger.Trace("Git Installation folder {0} discovered: '{1}'", path == null ? "not" : "", path);
118+
if (path == null)
119+
{
120+
Logger.Trace("Git Installation not discovered");
121+
}
122+
else
123+
{
124+
Logger.Trace("Git Installation discovered: '{0}'", path);
125+
}
115126

116127
return path;
117128
}
118129

119130
private Task<NPath> LookForPortableGit()
120131
{
132+
Logger.Trace("LookForPortableGit");
133+
121134
var gitHubLocalAppDataPath = environment.UserCachePath;
122135
if (!gitHubLocalAppDataPath.DirectoryExists())
123136
return null;
@@ -138,16 +151,22 @@ private Task<NPath> LookForPortableGit()
138151

139152
private async Task<NPath> LookForSystemGit()
140153
{
154+
Logger.Trace("LookForSystemGit");
155+
141156
NPath path = null;
142157
if (!environment.IsWindows)
143158
{
144159
var p = new NPath("/usr/local/bin/git");
160+
145161
if (p.FileExists())
146162
path = p;
147163
}
148164

149165
if (path == null)
150-
path = await new FindExecTask("git", taskManager.Token).StartAwait();
166+
{
167+
path = await new FindExecTask("git", taskManager.Token)
168+
.Configure(processManager).StartAwait();
169+
}
151170

152171
return path;
153172
}
@@ -172,11 +191,10 @@ public ITask<ValidateGitInstallResult> ValidateGitInstall(string path)
172191
gitLfsVersionTask.ProcessArguments, environment.RepositoryPath);
173192

174193
return gitVersionTask
175-
.Then((result, version) => { gitVersion = version; })
194+
.Then((result, version) => gitVersion = version)
176195
.Then(gitLfsVersionTask)
177-
.Then((result, version) => {
178-
gitLfsVersion = version;
179-
}).Then(result => {
196+
.Then((result, version) => gitLfsVersion = version)
197+
.Then(result => {
180198
var b = result
181199
&& gitVersion != null
182200
&& gitVersion >= Constants.MinimumGitVersion

src/GitHub.Api/Git/GitCredentialManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ private async Task<bool> LoadCredentialHelper()
133133
.Configure(processManager)
134134
.StartAwait();
135135

136+
Logger.Trace("Loaded Credential Helper: {0}", credHelper);
137+
136138
if (credHelper != null)
137139
{
138140
return true;

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,16 @@ public ITask LockFile(string file)
312312
{
313313
var task = GitClient.Lock(file);
314314
HookupHandlers(task);
315-
ListLocks(false);
316-
return task;
315+
316+
return task.Then(ListLocks(false));
317317
}
318318

319319
public ITask UnlockFile(string file, bool force)
320320
{
321321
var task = GitClient.Unlock(file, force);
322322
HookupHandlers(task).Schedule(taskManager);
323-
ListLocks(false);
324-
return task;
323+
324+
return task.Then(ListLocks(false));
325325
}
326326

327327
private void LoadGitUser()

src/GitHub.Api/OutputProcessors/LfsVersionOutputProcessor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
using System;
2+
using System.Text.RegularExpressions;
23

34
namespace GitHub.Unity
45
{
56
class LfsVersionOutputProcessor : BaseOutputProcessor<Version>
67
{
8+
public static Regex GitLfsVersionRegex = new Regex(@"git-lfs/([\d]+)\.([\d]+)\.([\d]+)");
9+
710
public override void LineReceived(string line)
811
{
912
if (String.IsNullOrEmpty(line))
1013
return;
1114

12-
var gitVersion = "git-lfs/";
13-
if (line.StartsWith(gitVersion))
14-
{
15-
line = line.Substring(gitVersion.Length, line.IndexOf(" ", StringComparison.InvariantCultureIgnoreCase) - gitVersion.Length);
16-
var strings = line.Split(new[] { "." }, StringSplitOptions.None);
15+
var match = GitLfsVersionRegex.Match(line);
1716

18-
RaiseOnEntry(new Version(Int32.Parse(strings[0]), Int32.Parse(strings[1]), Int32.Parse(strings[2])));
17+
if (match.Groups.Count > 0)
18+
{
19+
var major = Int32.Parse(match.Groups[1].Value);
20+
var minor = Int32.Parse(match.Groups[2].Value);
21+
var build = Int32.Parse(match.Groups[3].Value);
22+
var version = new Version(major, minor, build);
23+
RaiseOnEntry(version);
1924
}
2025
}
2126
}

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,28 @@ public ProcessManager(IEnvironment environment, IProcessEnvironment gitEnvironme
2424

2525
public T Configure<T>(T processTask, bool withInput = false) where T : IProcess
2626
{
27+
NPath executableFileName;
28+
if (processTask.ProcessName != null)
29+
{
30+
executableFileName = processTask.ProcessName.ToNPath();
31+
//logger.Trace("Configuring Task:{0} with Exec:{1}", processTask.GetType().Name, executableFileName);
32+
}
33+
else
34+
{
35+
executableFileName = environment.GitExecutablePath;
36+
//logger.Trace("Configuring Task:{0} with Git", processTask.GetType().Name);
37+
}
38+
2739
return Configure(processTask,
28-
processTask.ProcessName?.ToNPath() ?? environment.GitExecutablePath,
40+
executableFileName,
2941
processTask.ProcessArguments,
3042
environment.RepositoryPath, withInput);
3143
}
3244

3345
public T Configure<T>(T processTask, string executableFileName, string arguments, NPath workingDirectory = null, bool withInput = false)
3446
where T : IProcess
3547
{
48+
//If this null check fails, be sure you called Configure() on your task
3649
Guard.ArgumentNotNull(executableFileName, nameof(executableFileName));
3750

3851
var startInfo = new ProcessStartInfo

src/GitHub.Api/OutputProcessors/VersionOutputProcessor.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
35

46
namespace GitHub.Unity
57
{
68
class VersionOutputProcessor : BaseOutputProcessor<Version>
79
{
10+
public static Regex GitVersionRegex = new Regex(@"git version ([\d]+)\.([\d]+)\.([\d]+)");
11+
812
public override void LineReceived(string line)
913
{
1014
if (String.IsNullOrEmpty(line))
1115
return;
1216

13-
var gitVersion = "git version ";
14-
if (line.StartsWith(gitVersion))
15-
{
16-
line = line.Substring(gitVersion.Length);
17-
var strings = line.Split(new[] { "." }, StringSplitOptions.None);
17+
var match = GitVersionRegex.Match(line);
1818

19-
RaiseOnEntry(new Version(Int32.Parse(strings[0]), Int32.Parse(strings[1]), Int32.Parse(strings[2])));
19+
if (match.Groups.Count > 0)
20+
{
21+
var major = Int32.Parse(match.Groups[1].Value);
22+
var minor = Int32.Parse(match.Groups[2].Value);
23+
var build = Int32.Parse(match.Groups[3].Value);
24+
var version = new Version(major, minor, build);
25+
RaiseOnEntry(version);
2026
}
2127
}
2228
}

src/GitHub.Api/Platform/FindExecTask.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public FindExecTask(string executable, CancellationToken token)
1313
arguments = executable;
1414
}
1515

16+
public override string ProcessName { get { return Name; } }
1617
public override string ProcessArguments { get { return arguments; } }
1718
public override TaskAffinity Affinity { get { return TaskAffinity.Concurrent; } }
1819
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BranchesView : Subview
5252
[SerializeField] private List<Remote> remotes = new List<Remote>();
5353
[SerializeField] private Vector2 scroll;
5454
[SerializeField] private BranchTreeNode selectedNode;
55-
private List<string> favoritesList;
55+
[SerializeField] private List<string> favoritesList = new List<string>();
5656

5757
public override void InitializeView(IView parent)
5858
{

0 commit comments

Comments
 (0)