feat: delete orphan remote tracking branches (#692)

* feat: remove orphan remote-tracking branches

- Allow user remove local remote-tracking branches without remotes (ie. remote was removed on merge request).
- Included 'DeleteRemoteTracking' and 'HasRemote' util methods to handle this case.

* fix: delete both case (local & remote-tracking)

- We have local and remote-tracking but not a remote branch. We need to remove both or only the tracking based on the checkbox and on the 'hasRemote' condition
This commit is contained in:
Alberto de la Cruz 2024-11-13 02:33:35 +01:00 committed by GitHub
parent c16a412aa3
commit 8935bdd4c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 4 deletions

View file

@ -52,5 +52,27 @@
cmd.Args = $"push {remote} --delete {name}";
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;
}
}
}