Skip to content

Commit c8bee2f

Browse files
committed
code_review: PR #1093
Merge deleting branch and tag on remote into `SourceGit.Commands.Push(repo, remote, refname, isDelete)` Signed-off-by: leo <[email protected]>
1 parent 9645b65 commit c8bee2f

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

src/Commands/Branch.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,14 @@ public static bool DeleteLocal(string repo, string name)
5454

5555
public static bool DeleteRemote(string repo, string remote, string name)
5656
{
57-
var cmd = new Command();
58-
cmd.WorkingDirectory = repo;
59-
cmd.Context = repo;
60-
6157
bool exists = new Remote(repo).HasBranch(remote, name);
6258
if (exists)
63-
{
64-
cmd.SSHKey = new Config(repo).Get($"remote.{remote}.sshkey");
65-
cmd.Args = $"push {remote} --delete refs/heads/{name}";
66-
}
67-
else
68-
{
69-
cmd.Args = $"branch -D -r {remote}/{name}";
70-
}
59+
return new Push(repo, remote, $"refs/heads/{name}", true).Exec();
7160

61+
var cmd = new Command();
62+
cmd.WorkingDirectory = repo;
63+
cmd.Context = repo;
64+
cmd.Args = $"branch -D -r {remote}/{name}";
7265
return cmd.Exec();
7366
}
7467
}

src/Commands/Push.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Push(string repo, string local, string remote, string remoteBranch, bool
2626
Args += $"{remote} {local}:{remoteBranch}";
2727
}
2828

29-
public Push(string repo, string remote, string tag, bool isDelete)
29+
public Push(string repo, string remote, string refname, bool isDelete)
3030
{
3131
WorkingDirectory = repo;
3232
Context = repo;
@@ -36,7 +36,7 @@ public Push(string repo, string remote, string tag, bool isDelete)
3636
if (isDelete)
3737
Args += "--delete ";
3838

39-
Args += $"{remote} refs/tags/{tag}";
39+
Args += $"{remote} {refname}";
4040
}
4141

4242
protected override void OnReadline(string line)

src/Commands/Tag.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public static bool Delete(string repo, string name, List<Models.Remote> remotes)
4848
if (remotes != null)
4949
{
5050
foreach (var r in remotes)
51-
{
52-
new Push(repo, r.Name, name, true).Exec();
53-
}
51+
new Push(repo, r.Name, $"refs/tags/{name}", true).Exec();
5452
}
5553

5654
return true;

src/ViewModels/CreateTag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override Task<bool> Sure()
9696
foreach (var remote in remotes)
9797
{
9898
SetProgressDescription($"Pushing tag to remote {remote.Name} ...");
99-
new Commands.Push(_repo.FullPath, remote.Name, _tagName, false).Exec();
99+
new Commands.Push(_repo.FullPath, remote.Name, $"refs/tags/{_tagName}", false).Exec();
100100
}
101101
}
102102

src/ViewModels/PushTag.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,22 @@ public override Task<bool> Sure()
4343

4444
return Task.Run(() =>
4545
{
46-
bool succ = true;
46+
var succ = true;
47+
var tag = $"refs/tags/{Target.Name}";
4748
if (_pushAllRemotes)
4849
{
4950
foreach (var remote in _repo.Remotes)
5051
{
5152
SetProgressDescription($"Pushing tag to remote {remote.Name} ...");
52-
succ = new Commands.Push(_repo.FullPath, remote.Name, Target.Name, false).Exec();
53+
succ = new Commands.Push(_repo.FullPath, remote.Name, tag, false).Exec();
5354
if (!succ)
5455
break;
5556
}
5657
}
5758
else
5859
{
5960
SetProgressDescription($"Pushing tag to remote {SelectedRemote.Name} ...");
60-
succ = new Commands.Push(_repo.FullPath, SelectedRemote.Name, Target.Name, false).Exec();
61+
succ = new Commands.Push(_repo.FullPath, SelectedRemote.Name, tag, false).Exec();
6162
}
6263

6364
CallUIThread(() => _repo.SetWatcherEnabled(true));

0 commit comments

Comments
 (0)