sourcegit/src/SourceGit/Commands/QueryRemotes.cs

41 lines
1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2021-04-29 05:05:55 -07:00
using System.Text.RegularExpressions;
namespace SourceGit.Commands
{
public partial class QueryRemotes : Command
{
2024-03-16 02:09:27 -07:00
[GeneratedRegex(@"^([\w\.\-]+)\s*(\S+).*$")]
private static partial Regex REG_REMOTE();
2021-04-29 05:05:55 -07:00
public QueryRemotes(string repo)
{
WorkingDirectory = repo;
Context = repo;
2021-04-29 05:05:55 -07:00
Args = "remote -v";
}
public List<Models.Remote> Result()
{
2021-04-29 05:05:55 -07:00
Exec();
return _loaded;
2021-04-29 05:05:55 -07:00
}
protected override void OnReadline(string line)
{
2024-03-16 02:09:27 -07:00
var match = REG_REMOTE().Match(line);
2021-04-29 05:05:55 -07:00
if (!match.Success) return;
var remote = new Models.Remote()
{
2021-04-29 05:05:55 -07:00
Name = match.Groups[1].Value,
URL = match.Groups[2].Value,
};
if (_loaded.Find(x => x.Name == remote.Name) != null) return;
_loaded.Add(remote);
2021-04-29 05:05:55 -07:00
}
private readonly List<Models.Remote> _loaded = new List<Models.Remote>();
2021-04-29 05:05:55 -07:00
}
}