Skip to content

Commit 74e1578

Browse files
committed
fix: editing remote in settings pages now works if you are adding, updating, or removing the remote.
adds the constraint that we only operate on a single remote named origin. previously multiple remotes had undefined behavior.
1 parent 88fb29b commit 74e1578

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Fixed
1414
- Deletes are now properly owned by the user who did the delete (#729)
1515
- Pull page output now displays better when pull preview shows a lot of changes (#740)
16+
- Changing remotes in the git project settings pages now works if remote is not already defined (#746)
1617

1718
## [2.11.0] - 2025-04-23
1819

cls/SourceControl/Git/Utils.cls

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,15 +3019,23 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
30193019
return sc
30203020
}
30213021

3022-
/// Returns the url for the remote repository (censoring the username)
3023-
ClassMethod GetConfiguredRemote() As %String
3024-
{
3025-
d ..RunGitCommand("remote",.err,.out,"-v")
3026-
set line = out.ReadLine()
3027-
set url = $piece($piece(line,$char(9),2)," ",1)
3022+
/// Returns the url for the "origin" remote repository
3023+
ClassMethod GetConfiguredRemote(Output remoteExists As %Boolean = 0) As %String
3024+
{
3025+
set exitCode = ..RunGitCommand("remote",.err,.out,"get-url","origin")
3026+
if (exitCode = 0) {
3027+
set remoteExists = 1
3028+
set url = out.ReadLine()
3029+
} elseif (exitCode = 2) {
3030+
set remoteExists = 0
3031+
set url = ""
3032+
} else {
3033+
$$$ThrowStatus($$$ERROR($$$GeneralError,"git reported failure"))
3034+
}
30283035
return url
30293036
}
30303037

3038+
/// Returns the url for the "origin" remote repository, redacting the username
30313039
ClassMethod GetRedactedRemote() As %String
30323040
{
30333041
set url = ..GetConfiguredRemote()
@@ -3038,7 +3046,15 @@ ClassMethod GetRedactedRemote() As %String
30383046

30393047
ClassMethod SetConfiguredRemote(url) As %String
30403048
{
3041-
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"set-url","origin",url)
3049+
do ..GetConfiguredRemote(.remoteExists)
3050+
set returnCode = $select(
3051+
remoteExists&&(url=""): ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"remove","origin"),
3052+
remoteExists&&(url'=""): ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"set-url","origin",url),
3053+
'remoteExists&&(url'=""): ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"add","origin",url),
3054+
1: 0)
3055+
if (returnCode '= 0) {
3056+
$$$ThrowStatus($$$ERROR($$$GeneralError,"git reported failure"))
3057+
}
30423058
set output = outStream.ReadLine(outStream.Size)
30433059
quit output
30443060
}
@@ -3198,4 +3214,3 @@ ClassMethod IsSchemaStandard(pName As %String = "") As %Boolean [ Internal ]
31983214
}
31993215

32003216
}
3201-

0 commit comments

Comments
 (0)