2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
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
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public QueryRemotes(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = "remote -v";
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Remote> Result()
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return _loaded;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
var match = REG_REMOTE().Match(line);
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!match.Success)
|
|
|
|
|
return;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
var remote = new Models.Remote()
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Name = match.Groups[1].Value,
|
|
|
|
|
URL = match.Groups[2].Value,
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_loaded.Find(x => x.Name == remote.Name) != null)
|
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_loaded.Add(remote);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly List<Models.Remote> _loaded = new List<Models.Remote>();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|