Skip to content

Commit 5099279

Browse files
committed
working towards iris sync solution
1 parent 8d41e1c commit 5099279

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

cls/SourceControl/Git/Utils.cls

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
15771577

15781578
ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer
15791579
{
1580+
15801581
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
15811582
if (command '= "--version") {
15821583
set newArgs($increment(newArgs)) = "-C"
@@ -1604,16 +1605,34 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16041605

16051606
set newArgs($increment(newArgs)) = command
16061607

1608+
1609+
1610+
if (command = "checkout") || (command = "merge") || (command = "rebase") {
1611+
set syncIris = 1
1612+
set diffCompare = args(args)
1613+
set diffBase = ""
1614+
}
1615+
1616+
16071617
for i=1:1:$get(args) {
16081618
if ($data(args(i))) {
16091619
set newArgs($increment(newArgs)) = args(i)
1620+
if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") {
1621+
set syncIris = 1
1622+
set diffCompare = args(i + 1)
1623+
set diffBase = ""
1624+
if $LISTLENGTH(args) = (i + 2) {
1625+
set diffBase = args(i + 2)
1626+
}
1627+
}
16101628
}
16111629
}
16121630

16131631
set outLog = ##class(%Library.File).TempFilename()
16141632
set errLog = ##class(%Library.File).TempFilename()
16151633

16161634
set command = $extract(..GitBinPath(),2,*-1)
1635+
16171636
set baseArgs = "/STDOUT="_$$$QUOTE(outLog)_" /STDERR="_$$$QUOTE(errLog)_$case(inFile, "":"", :" /STDIN="_$$$QUOTE(inFile))
16181637
try {
16191638
// Inject instance manager directory as global git config home directory
@@ -1635,9 +1654,87 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16351654
for stream=errStream,outStream {
16361655
set stream.RemoveOnClose = 1
16371656
}
1657+
1658+
if syncIris {
1659+
if diffBase = "" {
1660+
set diffBase = ..GetCurrentBranch()
1661+
}
1662+
do ..SyncIrisWithRepo(diffBase, diffCompare)
1663+
}
16381664
quit returnCode
16391665
}
16401666

1667+
ClassMethod SyncIrisWithRepo(diffBase As %String, diffCompare As %String)
1668+
{
1669+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errStream,.outStream, diffBase_".."_diffCompare, "--name-status")
1670+
while (outStream.AtEnd = 0) {
1671+
set file = outStream.ReadLine()
1672+
set modification = ##class(SourceControl.Git.Modification).%New()
1673+
set modification.changeType = $piece(file, $c(9), 1)
1674+
set modification.externalName = $zstrip($piece(file, $c(9),2),"<W")
1675+
if (modification.changeType '= "A"){
1676+
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
1677+
}
1678+
else {
1679+
set modification.internalName = ""
1680+
}
1681+
set files($increment(files)) = modification
1682+
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
1683+
}
1684+
if ('$data(files)) {
1685+
write !, ?4, "None"
1686+
if preview {
1687+
quit $$$OK
1688+
}
1689+
write !, "Already up to date."
1690+
quit $$$OK
1691+
} elseif preview {
1692+
quit $$$OK
1693+
}
1694+
1695+
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
1696+
if (sc=1){
1697+
do ..PrintStreams(errStream, outStream)
1698+
quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.")
1699+
}
1700+
do ..PrintStreams(outStream)
1701+
write !
1702+
1703+
set key = $order(files(""))
1704+
set deletedFiles = ""
1705+
set addedFiles = ""
1706+
while(key '= "") {
1707+
set modification = files(key)
1708+
if (modification.changeType = "D"){
1709+
if (modification.internalName '= "") {
1710+
set deletedFiles = deletedFiles_","_modification.internalName
1711+
}
1712+
} elseif (modification.changeType = "A"){
1713+
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
1714+
if (modification.internalName '= "") {
1715+
set addedFiles = addedFiles_","_modification.internalName
1716+
set files(key) = modification
1717+
}
1718+
}
1719+
set key = $order(files(key))
1720+
}
1721+
1722+
set deletedFiles = $extract(deletedFiles, 2, *)
1723+
set addedFiles = $extract(addedFiles, 2, *)
1724+
1725+
if (deletedFiles '= ""){
1726+
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
1727+
}
1728+
if (addedFiles '= ""){
1729+
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
1730+
}
1731+
1732+
set event = $classmethod(..PullEventClass(),"%New")
1733+
set event.LocalRoot = ..TempFolder()
1734+
merge event.ModifiedFiles = files
1735+
quit event.OnPull()
1736+
}
1737+
16411738
ClassMethod GenerateCommitMessageFromFiles(filesWithActions) As %String
16421739
{
16431740
set commitMsg = ""

0 commit comments

Comments
 (0)