2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class Remote : Command
|
|
|
|
|
{
|
|
|
|
|
public Remote(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Add(string name, string url)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"remote add {name} {url}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Delete(string name)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"remote remove {name}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Rename(string name, string to)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"remote rename {name} {to}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Prune(string name)
|
|
|
|
|
{
|
2021-11-17 00:12:26 -08:00
|
|
|
|
Args = $"remote prune {name}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 19:03:42 -07:00
|
|
|
|
public string GetURL(string name, bool isPush)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-10-10 19:03:42 -07:00
|
|
|
|
Args = "remote get-url" + (isPush ? " --push " : " ") + name;
|
|
|
|
|
|
|
|
|
|
var rs = ReadToEnd();
|
|
|
|
|
return rs.IsSuccess ? rs.StdOut.Trim() : string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetURL(string name, string url, bool isPush)
|
|
|
|
|
{
|
|
|
|
|
Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
}
|
2024-11-12 18:04:28 -08:00
|
|
|
|
|
|
|
|
|
public bool HasBranch(string remote, string branch)
|
|
|
|
|
{
|
|
|
|
|
SSHKey = new Config(WorkingDirectory).Get($"remote.{remote}.sshkey");
|
|
|
|
|
Args = $"ls-remote {remote} {branch}";
|
|
|
|
|
|
|
|
|
|
var rs = ReadToEnd();
|
|
|
|
|
return rs.IsSuccess && rs.StdOut.Trim().Length > 0;
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|