2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public static class Branch
|
|
|
|
|
{
|
2024-12-09 23:17:54 -08:00
|
|
|
|
public static string ShowCurrent(string repo)
|
|
|
|
|
{
|
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
|
|
|
|
cmd.Args = $"branch --show-current";
|
|
|
|
|
return cmd.ReadToEnd().StdOut.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool Create(string repo, string name, string basedOn)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
|
|
|
|
cmd.Args = $"branch {name} {basedOn}";
|
|
|
|
|
return cmd.Exec();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool Rename(string repo, string name, string to)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
|
|
|
|
cmd.Args = $"branch -M {name} {to}";
|
|
|
|
|
return cmd.Exec();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool SetUpstream(string repo, string name, string upstream)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
2024-07-09 03:13:15 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (string.IsNullOrEmpty(upstream))
|
2024-02-05 23:08:37 -08:00
|
|
|
|
cmd.Args = $"branch {name} --unset-upstream";
|
2024-03-17 18:37:06 -07:00
|
|
|
|
else
|
2024-02-05 23:08:37 -08:00
|
|
|
|
cmd.Args = $"branch {name} -u {upstream}";
|
2024-07-09 03:13:15 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return cmd.Exec();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 18:58:06 -07:00
|
|
|
|
public static bool DeleteLocal(string repo, string name)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
|
|
|
|
cmd.Args = $"branch -D {name}";
|
|
|
|
|
return cmd.Exec();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-05-20 18:58:06 -07:00
|
|
|
|
|
|
|
|
|
public static bool DeleteRemote(string repo, string remote, string name)
|
|
|
|
|
{
|
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
2024-11-12 17:33:35 -08:00
|
|
|
|
|
2024-11-12 18:04:28 -08:00
|
|
|
|
bool exists = new Remote(repo).HasBranch(remote, name);
|
|
|
|
|
if (exists)
|
|
|
|
|
{
|
|
|
|
|
cmd.SSHKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
|
|
|
cmd.Args = $"push {remote} --delete {name}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd.Args = $"branch -D -r {remote}/{name}";
|
|
|
|
|
}
|
2024-11-12 17:33:35 -08:00
|
|
|
|
|
2024-11-12 18:04:28 -08:00
|
|
|
|
return cmd.Exec();
|
2024-11-12 17:33:35 -08:00
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|