2024-02-05 23:08:37 -08:00
|
|
|
|
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
|
|
|
|
|
2024-02-05 23:08:37 -08: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();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return _loaded;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08: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,
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (_loaded.Find(x => x.Name == remote.Name) != null) return;
|
|
|
|
|
_loaded.Add(remote);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
private List<Models.Remote> _loaded = new List<Models.Remote>();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|