Skip to content

Sync with iris for all local repo changes #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cls/SourceControl/Git/API.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -65,3 +65,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
}

}

191 changes: 114 additions & 77 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -1633,16 +1565,76 @@ 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)
}
}

set outLog = ##class(%Library.File).TempFilename()
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
Expand All @@ -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 = ""
Expand Down
5 changes: 4 additions & 1 deletion cls/_zpkg/isc/sc/git/Socket.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading