sourcegit/src/Commands/QueryRemotes.cs

35 lines
996 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 {
public class QueryRemotes : Command {
2021-04-29 05:05:55 -07:00
private static readonly Regex REG_REMOTE = new Regex(@"^([\w\.\-]+)\s*(\S+).*$");
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) {
2021-04-29 05:05:55 -07:00
var match = REG_REMOTE.Match(line);
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
}
}