diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ae3915..be4dbfb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Expanded Baseline Export to include custom HL7, X12, ASTM schemas and Lookup Tables (#693) +- Settings page includes a test of the connection to the remote (#746) ### Fixed - Deletes are now properly owned by the user who did the delete (#729) - Pull page output now displays better when pull preview shows a lot of changes (#740) +- Changing remotes in the git project settings pages now works if remote is not already defined (#746) ## [2.11.0] - 2025-04-23 diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index ce372070..7dd27455 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -3019,15 +3019,23 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status return sc } -/// Returns the url for the remote repository (censoring the username) -ClassMethod GetConfiguredRemote() As %String -{ - d ..RunGitCommand("remote",.err,.out,"-v") - set line = out.ReadLine() - set url = $piece($piece(line,$char(9),2)," ",1) +/// Returns the url for the "origin" remote repository +ClassMethod GetConfiguredRemote(Output remoteExists As %Boolean = 0) As %String +{ + set exitCode = ..RunGitCommand("remote",.err,.out,"get-url","origin") + if (exitCode = 0) { + set remoteExists = 1 + set url = out.ReadLine() + } elseif (exitCode = 2) { + set remoteExists = 0 + set url = "" + } else { + $$$ThrowStatus($$$ERROR($$$GeneralError,"git reported failure")) + } return url } +/// Returns the url for the "origin" remote repository, redacting the username ClassMethod GetRedactedRemote() As %String { set url = ..GetConfiguredRemote() @@ -3038,7 +3046,15 @@ ClassMethod GetRedactedRemote() As %String ClassMethod SetConfiguredRemote(url) As %String { - do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"set-url","origin",url) + do ..GetConfiguredRemote(.remoteExists) + set returnCode = $select( + remoteExists&&(url=""): ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"remove","origin"), + remoteExists&&(url'=""): ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"set-url","origin",url), + 'remoteExists&&(url'=""): ##class(SourceControl.Git.Utils).RunGitCommandWithInput("remote",,.errStream,.outStream,"add","origin",url), + 1: 0) + if (returnCode '= 0) { + $$$ThrowStatus($$$ERROR($$$GeneralError,"git reported failure")) + } set output = outStream.ReadLine(outStream.Size) quit output } @@ -3198,4 +3214,3 @@ ClassMethod IsSchemaStandard(pName As %String = "") As %Boolean [ Internal ] } } - diff --git a/csp/gitprojectsettings.csp b/csp/gitprojectsettings.csp index e33b5ca2..171ed7ef 100644 --- a/csp/gitprojectsettings.csp +++ b/csp/gitprojectsettings.csp @@ -11,6 +11,7 @@