From 5099279817ebed1946b07e55c5397e0a90ea4ce6 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Fri, 21 Jun 2024 09:18:41 -0400 Subject: [PATCH 01/15] working towards iris sync solution --- cls/SourceControl/Git/Utils.cls | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 196f1e71..0d607ae2 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -1577,6 +1577,7 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer { + // 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" @@ -1604,9 +1605,26 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O set newArgs($increment(newArgs)) = command + + + if (command = "checkout") || (command = "merge") || (command = "rebase") { + set syncIris = 1 + set diffCompare = args(args) + set diffBase = "" + } + + for i=1:1:$get(args) { if ($data(args(i))) { set newArgs($increment(newArgs)) = args(i) + if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") { + set syncIris = 1 + set diffCompare = args(i + 1) + set diffBase = "" + if $LISTLENGTH(args) = (i + 2) { + set diffBase = args(i + 2) + } + } } } @@ -1614,6 +1632,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 @@ -1635,9 +1654,87 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O for stream=errStream,outStream { set stream.RemoveOnClose = 1 } + + if syncIris { + if diffBase = "" { + set diffBase = ..GetCurrentBranch() + } + do ..SyncIrisWithRepo(diffBase, diffCompare) + } quit returnCode } +ClassMethod SyncIrisWithRepo(diffBase As %String, diffCompare As %String) +{ + do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errStream,.outStream, diffBase_".."_diffCompare, "--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)," Date: Fri, 21 Jun 2024 15:16:46 -0400 Subject: [PATCH 02/15] iris sync implemented --- cls/SourceControl/Git/Utils.cls | 76 ++++++++++++++------------------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 0d607ae2..01d888cc 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -1605,29 +1605,53 @@ 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 = "" if (command = "checkout") || (command = "merge") || (command = "rebase") { set syncIris = 1 set diffCompare = args(args) - set diffBase = "" } - + for i=1:1:$get(args) { if ($data(args(i))) { set newArgs($increment(newArgs)) = args(i) if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") { set syncIris = 1 set diffCompare = args(i + 1) - set diffBase = "" - if $LISTLENGTH(args) = (i + 2) { + + if args = (i + 2) { set diffBase = args(i + 2) } } } } + if syncIris { + if diffBase = "" { + set diffBase = ..GetCurrentBranch() + } + 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)," Date: Fri, 21 Jun 2024 16:12:36 -0400 Subject: [PATCH 03/15] fixed bug with merges --- cls/SourceControl/Git/Utils.cls | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 01d888cc..27ca987d 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -1608,7 +1608,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O // defining variables for if statement use later set syncIris = 0 set diffBase = "" - + set diffCompare = "" if (command = "checkout") || (command = "merge") || (command = "rebase") { set syncIris = 1 set diffCompare = args(args) @@ -1629,10 +1629,16 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O } } + if (diffCompare = "--no-commit") || (diffCompare = "--abort") { + set syncIris = 0 + } + if syncIris { + set ^mtemphw("diffc", $i(^mtemphw("diffc"))) = diffCompare if diffBase = "" { set diffBase = ..GetCurrentBranch() } + set ^mtemphw("diffb", $i(^mtemphw("diffb"))) = diffBase do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_".."_diffCompare, "--name-status") while (outputStream.AtEnd = 0) { set file = outputStream.ReadLine() From d0c3a5eec985141a30272104a578b04771bd140b Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Mon, 24 Jun 2024 10:03:16 -0400 Subject: [PATCH 04/15] added fetch before diff, removed redundant code in Pull() --- cls/SourceControl/Git/Utils.cls | 82 ++------------------------------- 1 file changed, 4 insertions(+), 78 deletions(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 27ca987d..fb20b1a3 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -446,82 +446,8 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat 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)," Date: Mon, 24 Jun 2024 12:30:57 -0400 Subject: [PATCH 05/15] now handles status returns and throws on error --- cls/SourceControl/Git/Utils.cls | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index fb20b1a3..c018bd9f 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -448,6 +448,7 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName) + quit sc } ClassMethod Clone(remote As %String) As %Status @@ -1613,7 +1614,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O if syncIris { - do ..SyncIrisWithRepo(.files) + $$$ThrowOnError(..SyncIrisWithRepo(.files)) + } quit returnCode } From ba01e48d1afe6f343e8f1d4dcb1574173a3dab4f Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Mon, 24 Jun 2024 15:42:25 -0400 Subject: [PATCH 06/15] fixed pull bug caused by diff --- cls/SourceControl/Git/Utils.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index c018bd9f..9fd271f8 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -446,7 +446,7 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat set branchName = outStream.ReadLine(outStream.Size) write !, "Pulling from branch: ", branchName - set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName) + set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName) quit sc } From 6d7b9717dcb0b183a262d7df6064e15b728de464 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Mon, 24 Jun 2024 16:27:34 -0400 Subject: [PATCH 07/15] addressed issue where pull doesn't work with preview --- cls/_zpkg/isc/sc/git/Socket.cls | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cls/_zpkg/isc/sc/git/Socket.cls b/cls/_zpkg/isc/sc/git/Socket.cls index 8c5e8dd0..3bc089a4 100644 --- a/cls/_zpkg/isc/sc/git/Socket.cls +++ b/cls/_zpkg/isc/sc/git/Socket.cls @@ -12,7 +12,8 @@ Property OriginalDevice; ClassMethod Run() { If %request.Get("method") = "preview" { - Do ##class(SourceControl.Git.API).Pull(1) + set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch() + do ..RunGitWithArgs(.errStream, .outStream, "pull", "origin/" _ branchName) } ElseIf %request.Get("method") = "pull" { Do ##class(SourceControl.Git.API).Pull() } ElseIf %request.Get("method") = "init" { From 0e9b877cdafac9eda78200158928688a66a50427 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Mon, 24 Jun 2024 16:28:22 -0400 Subject: [PATCH 08/15] addressed issue where pull doesn't work with preview --- cls/SourceControl/Git/API.cls | 5 ----- cls/SourceControl/Git/Utils.cls | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cls/SourceControl/Git/API.cls b/cls/SourceControl/Git/API.cls index 132e2d52..9d348d21 100644 --- a/cls/SourceControl/Git/API.cls +++ b/cls/SourceControl/Git/API.cls @@ -36,11 +36,6 @@ ClassMethod Configure() } } -/// API for git pull - just wraps Utils -ClassMethod Pull(preview As %Boolean = 0) -{ - quit ##class(SourceControl.Git.Utils).Pull(,.preview) -} /// Locks the environment to prevent changes to code other than through git pull. /// Returns 1 if the environment was already locked, 0 if it was previously unlocked. diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 9fd271f8..6a3c1622 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -439,7 +439,7 @@ 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") From 969dd41d03b77f0f1042a6808a6907d049d7736e Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Mon, 24 Jun 2024 16:31:58 -0400 Subject: [PATCH 09/15] added full class name in where it was ommitted --- cls/_zpkg/isc/sc/git/Socket.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cls/_zpkg/isc/sc/git/Socket.cls b/cls/_zpkg/isc/sc/git/Socket.cls index 3bc089a4..2836808f 100644 --- a/cls/_zpkg/isc/sc/git/Socket.cls +++ b/cls/_zpkg/isc/sc/git/Socket.cls @@ -13,7 +13,7 @@ ClassMethod Run() { If %request.Get("method") = "preview" { set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch() - do ..RunGitWithArgs(.errStream, .outStream, "pull", "origin/" _ branchName) + do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "pull", "origin/" _ branchName) } ElseIf %request.Get("method") = "pull" { Do ##class(SourceControl.Git.API).Pull() } ElseIf %request.Get("method") = "init" { From 785cc83259179abe01d1ff5512f36f08d40f8b5f Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Tue, 25 Jun 2024 10:10:33 -0400 Subject: [PATCH 10/15] readded pull method to api file --- cls/SourceControl/Git/API.cls | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cls/SourceControl/Git/API.cls b/cls/SourceControl/Git/API.cls index 9d348d21..9f244e77 100644 --- a/cls/SourceControl/Git/API.cls +++ b/cls/SourceControl/Git/API.cls @@ -36,6 +36,11 @@ ClassMethod Configure() } } +/// API for git pull - just wraps Utils +ClassMethod Pull() +{ + quit ##class(SourceControl.Git.Utils).Pull() +} /// Locks the environment to prevent changes to code other than through git pull. /// Returns 1 if the environment was already locked, 0 if it was previously unlocked. From 34c3e297ddc5d3864fd038028b87306541788ac4 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Tue, 25 Jun 2024 11:55:59 -0400 Subject: [PATCH 11/15] addressed issues with invalid pull request --- cls/SourceControl/Git/API.cls | 1 + cls/SourceControl/Git/Utils.cls | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cls/SourceControl/Git/API.cls b/cls/SourceControl/Git/API.cls index 9f244e77..0e10964e 100644 --- a/cls/SourceControl/Git/API.cls +++ b/cls/SourceControl/Git/API.cls @@ -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 6a3c1622..321b096b 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -446,9 +446,10 @@ ClassMethod Pull(remote As %String = "origin") As %Status set branchName = outStream.ReadLine(outStream.Size) write !, "Pulling from branch: ", branchName - set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName) + set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName) - quit sc + w !, "Pull ran with return code: " _ returnCode + quit $$$OK } ClassMethod Clone(remote As %String) As %Status @@ -1504,7 +1505,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" @@ -1536,6 +1540,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O 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) @@ -1545,6 +1550,9 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O 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) @@ -1553,6 +1561,10 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O set diffBase = args(i + 2) } } + + if (args(i) = "pull") { + set pullOriginIndex = i + } } } @@ -1583,6 +1595,10 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O set mod = files(files) write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName } + + if pullOriginIndex '= "" { + set newArgs(pullOriginIndex) = $piece(newArgs(pullOriginIndex), "/", 1) + } } set outLog = ##class(%Library.File).TempFilename() From 356accda8cdace6a371243989e433692f95bc2a9 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Tue, 25 Jun 2024 12:31:45 -0400 Subject: [PATCH 12/15] print outstreams in git command method --- cls/SourceControl/Git/Utils.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 321b096b..4768dcdd 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -445,9 +445,9 @@ ClassMethod Pull(remote As %String = "origin") As %Status do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outStream,"--show-current") set branchName = outStream.ReadLine(outStream.Size) write !, "Pulling from branch: ", branchName - + kill errStream, outStream set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName) - + w !, "Pull ran with return code: " _ returnCode quit $$$OK } @@ -1627,7 +1627,7 @@ 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)) From aa8c6e571e7e8c518b1c56d3d7f48854cac882f9 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Tue, 25 Jun 2024 13:43:54 -0400 Subject: [PATCH 13/15] fixed issues with Socket.Run() --- cls/_zpkg/isc/sc/git/Socket.cls | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cls/_zpkg/isc/sc/git/Socket.cls b/cls/_zpkg/isc/sc/git/Socket.cls index 2836808f..6c20ac2b 100644 --- a/cls/_zpkg/isc/sc/git/Socket.cls +++ b/cls/_zpkg/isc/sc/git/Socket.cls @@ -13,7 +13,9 @@ ClassMethod Run() { If %request.Get("method") = "preview" { set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch() - do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "pull", "origin/" _ branchName) + do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch") + kill errStream, outStream + do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "diff", "origin/"_branchName) } ElseIf %request.Get("method") = "pull" { Do ##class(SourceControl.Git.API).Pull() } ElseIf %request.Get("method") = "init" { From 5063ca0b9e7276980f766bcfa129157088eddc45 Mon Sep 17 00:00:00 2001 From: isc-hwojnick Date: Tue, 25 Jun 2024 13:45:26 -0400 Subject: [PATCH 14/15] added bug fix to changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc070595..446579bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added a new "Branch" parameter to `##class(SourceControl.Git.PullEventHandler)` (#351) - Command-line utility to do a baseline export of items in a namespace +### Fixed +- Modifications to local repo files are now synced with IRIS + ## [2.3.1] - 2024-04-30 From fa653949c7dbeabaafcb19fb75660cd2dd5d2bef Mon Sep 17 00:00:00 2001 From: Pravin Barton <9560941+isc-pbarton@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:14:03 -0400 Subject: [PATCH 15/15] Update cls/_zpkg/isc/sc/git/Socket.cls --- cls/_zpkg/isc/sc/git/Socket.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cls/_zpkg/isc/sc/git/Socket.cls b/cls/_zpkg/isc/sc/git/Socket.cls index 6c20ac2b..130972fd 100644 --- a/cls/_zpkg/isc/sc/git/Socket.cls +++ b/cls/_zpkg/isc/sc/git/Socket.cls @@ -15,7 +15,7 @@ ClassMethod Run() 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) + 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" {