diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a8e33e8..1dbba46d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Now skips files belonging to other git enabled packages in `##class(SourceControl.Git.Change).RefreshUncommitted()` (#347) - Added a new "Branch" parameter to `##class(SourceControl.Git.PullEventHandler)` (#351) - Command-line utility to do a baseline export of items in a namespace -- 'New Branch' menu option in basic now will create new branches from the configured default merge branch -- Merging back with the default merge branch is now a part of the basic mode's Sync flow +- 'New Branch' menu option in basic now will create new branches from the configured default merge branch (#366) +- Merging back with the default merge branch is now a part of the basic mode's Sync flow (#366) ### Fixed +- Modifications to local repo files are now synced with IRIS (#153) - Menu items names are properly translated from internal name in VSCode, Management Portal (#372) ## [2.3.1] - 2024-04-30 diff --git a/cls/SourceControl/Git/API.cls b/cls/SourceControl/Git/API.cls index 132e2d52..0e10964e 100644 --- a/cls/SourceControl/Git/API.cls +++ b/cls/SourceControl/Git/API.cls @@ -37,9 +37,9 @@ ClassMethod Configure() } /// API for git pull - just wraps Utils -ClassMethod Pull(preview As %Boolean = 0) +ClassMethod Pull() { - quit ##class(SourceControl.Git.Utils).Pull(,.preview) + quit ##class(SourceControl.Git.Utils).Pull() } /// Locks the environment to prevent changes to code other than through git pull. @@ -65,3 +65,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status } } + diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 5ed3bf0b..85791da9 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -468,89 +468,17 @@ ClassMethod GetCurrentBranch() As %String quit branchName } -ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Status +ClassMethod Pull(remote As %String = "origin") As %Status { #define Force 1 do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outStream,"--show-current") set branchName = outStream.ReadLine(outStream.Size) write !, "Pulling from branch: ", branchName - - set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName) - if (sc=1){ - do ..PrintStreams(errStream) - quit sc - } - - write !, "Fetch done" - write !, "Files that will be modified by git pull: " - - do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errStream,.outStream, branchName_".."_remote_"/"_branchName, "--name-status") - while (outStream.AtEnd = 0) { - set file = outStream.ReadLine() - set modification = ##class(SourceControl.Git.Modification).%New() - set modification.changeType = $piece(file, $c(9), 1) - set modification.externalName = $zstrip($piece(file, $c(9),2),"<W") - if (modification.changeType '= "A"){ - set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0) - } - else { - set modification.internalName = "" - } - set files($increment(files)) = modification - write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName - } - if ('$data(files)) { - write !, ?4, "None" - if preview { - quit $$$OK - } - write !, "Already up to date." - quit $$$OK - } elseif preview { - quit $$$OK - } - - set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName) - if (sc=1){ - do ..PrintStreams(errStream, outStream) - quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.") - } - do ..PrintStreams(outStream) - write ! - - set key = $order(files("")) - set deletedFiles = "" - set addedFiles = "" - while(key '= "") { - set modification = files(key) - if (modification.changeType = "D"){ - if (modification.internalName '= "") { - set deletedFiles = deletedFiles_","_modification.internalName - } - } elseif (modification.changeType = "A"){ - set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0) - if (modification.internalName '= "") { - set addedFiles = addedFiles_","_modification.internalName - set files(key) = modification - } - } - set key = $order(files(key)) - } - - set deletedFiles = $extract(deletedFiles, 2, *) - set addedFiles = $extract(addedFiles, 2, *) + kill errStream, outStream + set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName) - if (deletedFiles '= ""){ - set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles) - } - if (addedFiles '= ""){ - set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles) - } - - set event = $classmethod(..PullEventClass(),"%New") - set event.LocalRoot = ..TempFolder() - merge event.ModifiedFiles = files - quit event.OnPull() + w !, "Pull ran with return code: " _ returnCode + quit $$$OK } ClassMethod Clone(remote As %String) As %Status @@ -1606,6 +1534,10 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer { + set pullArg = "" + if command = "pull" { + set pullArg = args(1) + } // Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified. if (command '= "--version") { set newArgs($increment(newArgs)) = "-C" @@ -1633,9 +1565,68 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O set newArgs($increment(newArgs)) = command + // defining variables for if statement use later + set syncIris = 0 + set diffBase = "" + set diffCompare = "" + set pullOriginIndex = "" + if (command = "checkout") || (command = "merge") || (command = "rebase") || (command = "pull"){ + set syncIris = 1 + set diffCompare = args(args) + } + + for i=1:1:$get(args) { if ($data(args(i))) { set newArgs($increment(newArgs)) = args(i) + if newArgs(newArgs) = pullArg { + set pullOriginIndex = newArgs + } + if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull"){ + set syncIris = 1 + set diffCompare = args(i + 1) + + if args = (i + 2) { + set diffBase = args(i + 2) + } + } + + if (args(i) = "pull") { + set pullOriginIndex = i + } + } + } + + if (diffCompare = "--no-commit") || (diffCompare = "--abort") { + set syncIris = 0 + } + + if syncIris { + if diffBase = "" { + set diffBase = ..GetCurrentBranch() + } + do ..RunGitCommand("fetch", .errorStream, .outputStream) + kill errorStream, outputStream + do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_".."_diffCompare, "--name-status") + while (outputStream.AtEnd = 0) { + set file = outputStream.ReadLine() + set modification = ##class(SourceControl.Git.Modification).%New() + set modification.changeType = $piece(file, $c(9), 1) + + set modification.externalName = $zstrip($piece(file, $c(9),2),"<W") + if (modification.changeType '= "A"){ + set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0) + } + else { + set modification.internalName = "" + } + set files($increment(files)) = modification + set mod = files(files) + write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName + } + + if pullOriginIndex '= "" { + set newArgs(pullOriginIndex) = $piece(newArgs(pullOriginIndex), "/", 1) } } @@ -1643,6 +1634,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O set errLog = ##class(%Library.File).TempFilename() set command = $extract(..GitBinPath(),2,*-1) + set baseArgs = "/STDOUT="_$$$QUOTE(outLog)_" /STDERR="_$$$QUOTE(errLog)_$case(inFile, "":"", :" /STDIN="_$$$QUOTE(inFile)) try { // Inject instance manager directory as global git config home directory @@ -1664,9 +1656,54 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O for stream=errStream,outStream { set stream.RemoveOnClose = 1 } + do ..PrintStreams(errStream, outStream) + if syncIris { + + $$$ThrowOnError(..SyncIrisWithRepo(.files)) + + } quit returnCode } +ClassMethod SyncIrisWithRepo(ByRef files) +{ + + set key = $order(files("")) + set deletedFiles = "" + set addedFiles = "" + while(key '= "") { + set modification = files(key) + if (modification.changeType = "D"){ + if (modification.internalName '= "") { + set deletedFiles = deletedFiles_","_modification.internalName + } + } elseif (modification.changeType = "A"){ + set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0) + if (modification.internalName '= "") { + set addedFiles = addedFiles_","_modification.internalName + set files(key) = modification + + } + } + set key = $order(files(key)) + } + + set deletedFiles = $extract(deletedFiles, 2, *) + set addedFiles = $extract(addedFiles, 2, *) + + if (deletedFiles '= ""){ + set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles) + } + if (addedFiles '= ""){ + set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles) + } + + set event = $classmethod(..PullEventClass(),"%New") + set event.LocalRoot = ..TempFolder() + merge event.ModifiedFiles = files + quit event.OnPull() +} + ClassMethod GenerateCommitMessageFromFiles(filesWithActions) As %String { set commitMsg = "" diff --git a/cls/_zpkg/isc/sc/git/Socket.cls b/cls/_zpkg/isc/sc/git/Socket.cls index 8c5e8dd0..130972fd 100644 --- a/cls/_zpkg/isc/sc/git/Socket.cls +++ b/cls/_zpkg/isc/sc/git/Socket.cls @@ -12,7 +12,10 @@ Property OriginalDevice; ClassMethod Run() { If %request.Get("method") = "preview" { - Do ##class(SourceControl.Git.API).Pull(1) + set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch() + do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch") + kill errStream, outStream + do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "diff", "origin/"_branchName, "--name-status") } ElseIf %request.Get("method") = "pull" { Do ##class(SourceControl.Git.API).Pull() } ElseIf %request.Get("method") = "init" {