Skip to content

Commit c2b17ef

Browse files
committed
fix: changing the repository URL only changes the fetch URL if push URL using a different URL (sourcegit-scm#553)
1 parent 9370644 commit c2b17ef

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Commands/Remote.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ public bool Prune(string name)
3232
return Exec();
3333
}
3434

35-
public bool SetURL(string name, string url)
35+
public string GetURL(string name, bool isPush)
3636
{
37-
Args = $"remote set-url {name} {url}";
37+
Args = "remote get-url" + (isPush ? " --push " : " ") + name;
38+
39+
var rs = ReadToEnd();
40+
return rs.IsSuccess ? rs.StdOut.Trim() : string.Empty;
41+
}
42+
43+
public bool SetURL(string name, string url, bool isPush)
44+
{
45+
Args = "remote set-url" + (isPush ? " --push " : " ") + $"{name} {url}";
3846
return Exec();
3947
}
4048
}

src/ViewModels/EditRemote.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ public override Task<bool> Sure()
118118

119119
if (_remote.URL != _url)
120120
{
121-
var succ = new Commands.Remote(_repo.FullPath).SetURL(_name, _url);
121+
var succ = new Commands.Remote(_repo.FullPath).SetURL(_name, _url, false);
122122
if (succ)
123123
_remote.URL = _url;
124124
}
125125

126+
var pushURL = new Commands.Remote(_repo.FullPath).GetURL(_name, true);
127+
if (pushURL != _url)
128+
new Commands.Remote(_repo.FullPath).SetURL(_name, _url, true);
129+
126130
SetProgressDescription("Post processing ...");
127131
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
128132

0 commit comments

Comments
 (0)