-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathQueryRemotes.cs
More file actions
59 lines (50 loc) · 1.71 KB
/
QueryRemotes.cs
File metadata and controls
59 lines (50 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public partial class QueryRemotes : Command
{
[GeneratedRegex(@"^([\w\.\-]+)\s*(\S+).*$")]
private static partial Regex REG_REMOTE();
public QueryRemotes(string repo)
{
WorkingDirectory = repo;
Context = repo;
Args = "remote -v";
}
public async Task<List<Models.Remote>> GetResultAsync()
{
var outs = new List<Models.Remote>();
var rs = await ReadToEndAsync().ConfigureAwait(false);
if (!rs.IsSuccess)
return outs;
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
var match = REG_REMOTE().Match(line);
if (!match.Success)
continue;
var remote = new Models.Remote()
{
Name = match.Groups[1].Value,
URL = match.Groups[2].Value,
};
if (outs.Find(x => x.Name == remote.Name) != null)
continue;
if (remote.URL.StartsWith("git@", StringComparison.Ordinal))
{
var hostEnd = remote.URL.IndexOf(':', 4);
if (hostEnd > 4)
{
var host = remote.URL.Substring(4, hostEnd - 4);
Models.HTTPSValidator.Add(host);
}
}
outs.Add(remote);
}
return outs;
}
}
}