sourcegit/src/Commands/QueryRemotes.cs

36 lines
1,020 B
C#
Raw Normal View History

using System.Collections.Generic;
2021-04-29 05:05:55 -07:00
using System.Text.RegularExpressions;
namespace SourceGit.Commands {
2024-03-16 02:09:27 -07:00
public partial class QueryRemotes : Command {
[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() {
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() {
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 List<Models.Remote> _loaded = new List<Models.Remote>();
2021-04-29 05:05:55 -07:00
}
}