mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
refactor: implementation to delete branches
This commit is contained in:
parent
5eea54dbf8
commit
8fea9fecfb
3 changed files with 27 additions and 29 deletions
|
@ -36,7 +36,7 @@
|
||||||
return cmd.Exec();
|
return cmd.Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Delete(string repo, string name)
|
public static bool DeleteLocal(string repo, string name)
|
||||||
{
|
{
|
||||||
var cmd = new Command();
|
var cmd = new Command();
|
||||||
cmd.WorkingDirectory = repo;
|
cmd.WorkingDirectory = repo;
|
||||||
|
@ -44,5 +44,25 @@
|
||||||
cmd.Args = $"branch -D {name}";
|
cmd.Args = $"branch -D {name}";
|
||||||
return cmd.Exec();
|
return cmd.Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool DeleteRemote(string repo, string remote, string name)
|
||||||
|
{
|
||||||
|
var cmd = new Command();
|
||||||
|
cmd.WorkingDirectory = repo;
|
||||||
|
cmd.Context = repo;
|
||||||
|
|
||||||
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||||
|
if (!string.IsNullOrEmpty(sshKey))
|
||||||
|
{
|
||||||
|
cmd.Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmd.Args = "-c credential.helper=manager ";
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Args += $"push {remote} --delete {name}";
|
||||||
|
return cmd.Exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,31 +33,6 @@ namespace SourceGit.Commands
|
||||||
Args += $"{remote} {local}:{remoteBranch}";
|
Args += $"{remote} {local}:{remoteBranch}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Only used to delete a remote branch!!!!!!
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="repo"></param>
|
|
||||||
/// <param name="remote"></param>
|
|
||||||
/// <param name="branch"></param>
|
|
||||||
public Push(string repo, string remote, string branch)
|
|
||||||
{
|
|
||||||
WorkingDirectory = repo;
|
|
||||||
Context = repo;
|
|
||||||
TraitErrorAsOutput = true;
|
|
||||||
|
|
||||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
||||||
if (!string.IsNullOrEmpty(sshKey))
|
|
||||||
{
|
|
||||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Args = "-c credential.helper=manager ";
|
|
||||||
}
|
|
||||||
|
|
||||||
Args += $"push {remote} --delete {branch}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Push(string repo, string remote, string tag, bool isDelete)
|
public Push(string repo, string remote, string tag, bool isDelete)
|
||||||
{
|
{
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
|
|
@ -52,14 +52,17 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (Target.IsLocal)
|
if (Target.IsLocal)
|
||||||
{
|
{
|
||||||
Commands.Branch.Delete(_repo.FullPath, Target.Name);
|
Commands.Branch.DeleteLocal(_repo.FullPath, Target.Name);
|
||||||
|
|
||||||
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
||||||
new Commands.Push(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name).Exec();
|
{
|
||||||
|
SetProgressDescription("Deleting tracking remote branch...");
|
||||||
|
Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new Commands.Push(_repo.FullPath, Target.Remote, Target.Name).Exec();
|
Commands.Branch.DeleteRemote(_repo.FullPath, Target.Remote, Target.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
|
Loading…
Reference in a new issue