From c2b17ef9d032a3c23610c5c531b86c5ae5184bd5 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 11 Oct 2024 10:03:42 +0800 Subject: [PATCH] fix: changing the repository URL only changes the fetch URL if push URL using a different URL (#553) --- src/Commands/Remote.cs | 12 ++++++++++-- src/ViewModels/EditRemote.cs | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Commands/Remote.cs b/src/Commands/Remote.cs index 46aa37e3..f2e8d09e 100644 --- a/src/Commands/Remote.cs +++ b/src/Commands/Remote.cs @@ -32,9 +32,17 @@ return Exec(); } - public bool SetURL(string name, string url) + public string GetURL(string name, bool isPush) { - Args = $"remote set-url {name} {url}"; + Args = "remote get-url" + (isPush ? " --push " : " ") + name; + + var rs = ReadToEnd(); + return rs.IsSuccess ? rs.StdOut.Trim() : string.Empty; + } + + public bool SetURL(string name, string url, bool isPush) + { + Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}"; return Exec(); } } diff --git a/src/ViewModels/EditRemote.cs b/src/ViewModels/EditRemote.cs index 0a514324..912c7991 100644 --- a/src/ViewModels/EditRemote.cs +++ b/src/ViewModels/EditRemote.cs @@ -118,11 +118,15 @@ namespace SourceGit.ViewModels if (_remote.URL != _url) { - var succ = new Commands.Remote(_repo.FullPath).SetURL(_name, _url); + var succ = new Commands.Remote(_repo.FullPath).SetURL(_name, _url, false); if (succ) _remote.URL = _url; } + var pushURL = new Commands.Remote(_repo.FullPath).GetURL(_name, true); + if (pushURL != _url) + new Commands.Remote(_repo.FullPath).SetURL(_name, _url, true); + SetProgressDescription("Post processing ..."); new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);