mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-26 21:17:20 -08:00
code_review: PR #692
* remove unnecessary namespace using * move `Commands.Branch.HasRemote` to `Commands.Remote.HasBranch` * remove `Commands.Branch.DeleteRemoteTracking` and check branch in `Commands.Branch.DeleteRemote` directly Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
8935bdd4c9
commit
fd5c1f5105
3 changed files with 24 additions and 50 deletions
|
@ -48,31 +48,19 @@
|
||||||
var cmd = new Command();
|
var cmd = new Command();
|
||||||
cmd.WorkingDirectory = repo;
|
cmd.WorkingDirectory = repo;
|
||||||
cmd.Context = repo;
|
cmd.Context = repo;
|
||||||
cmd.SSHKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
||||||
cmd.Args = $"push {remote} --delete {name}";
|
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}";
|
||||||
|
}
|
||||||
|
|
||||||
return cmd.Exec();
|
return cmd.Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool DeleteRemoteTracking(string repo, string name)
|
|
||||||
{
|
|
||||||
var cmd = new Command();
|
|
||||||
cmd.WorkingDirectory = repo;
|
|
||||||
cmd.Context = repo;
|
|
||||||
cmd.Args = $"branch -D -r {name}";
|
|
||||||
return cmd.Exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool HasRemote(string repo, string remote, string name)
|
|
||||||
{
|
|
||||||
var cmd = new Command();
|
|
||||||
cmd.WorkingDirectory = repo;
|
|
||||||
cmd.Context = repo;
|
|
||||||
cmd.SSHKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
||||||
cmd.Args = $"ls-remote {remote} {name}";
|
|
||||||
|
|
||||||
var rs = cmd.ReadToEnd();
|
|
||||||
|
|
||||||
return rs.StdOut.Length > 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,14 @@
|
||||||
Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}";
|
Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}";
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
|
@ -57,34 +56,12 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
||||||
{
|
{
|
||||||
|
SetProgressDescription("Deleting remote-tracking branch...");
|
||||||
if (Commands.Branch.HasRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name))
|
Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name);
|
||||||
{
|
|
||||||
SetProgressDescription("Deleting remote-tracking branch and remote branch...");
|
|
||||||
|
|
||||||
Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetProgressDescription("Deleting remote-tracking branch...");
|
|
||||||
|
|
||||||
var remoteTrackingBranch = $"{TrackingRemoteBranch.Remote}/{TrackingRemoteBranch.Name}";
|
|
||||||
|
|
||||||
Commands.Branch.DeleteRemoteTracking(_repo.FullPath, remoteTrackingBranch);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!Commands.Branch.HasRemote(_repo.FullPath, Target.Remote, Target.Name))
|
|
||||||
{
|
|
||||||
SetProgressDescription("Remote branch not found. Deleting remote-tracking branch...");
|
|
||||||
var remoteTrackingBranch = $"{Target.Remote}/{Target.Name}";
|
|
||||||
|
|
||||||
Commands.Branch.DeleteRemoteTracking(_repo.FullPath, remoteTrackingBranch);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetProgressDescription("Deleting remote-tracking branch...");
|
|
||||||
Commands.Branch.DeleteRemote(_repo.FullPath, Target.Remote, Target.Name);
|
Commands.Branch.DeleteRemote(_repo.FullPath, Target.Remote, Target.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue