@@ -1577,6 +1577,7 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
1577
1577
1578
1578
ClassMethod RunGitCommandWithInput (command As %String , inFile As %String = " " , Output errStream , Output outStream , args ...) As %Integer
1579
1579
{
1580
+
1580
1581
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
1581
1582
if (command '= " --version" ) {
1582
1583
set newArgs ($increment (newArgs )) = " -C"
@@ -1604,16 +1605,34 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1604
1605
1605
1606
set newArgs ($increment (newArgs )) = command
1606
1607
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
+
1607
1617
for i =1 :1 :$get (args ) {
1608
1618
if ($data (args (i ))) {
1609
1619
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
+ }
1610
1628
}
1611
1629
}
1612
1630
1613
1631
set outLog = ##class (%Library.File ).TempFilename ()
1614
1632
set errLog = ##class (%Library.File ).TempFilename ()
1615
1633
1616
1634
set command = $extract (..GitBinPath (),2 ,*-1 )
1635
+
1617
1636
set baseArgs = " /STDOUT=" _$$$QUOTE(outLog )_" /STDERR=" _$$$QUOTE(errLog )_$case (inFile , " " :" " , :" /STDIN=" _$$$QUOTE(inFile ))
1618
1637
try {
1619
1638
// Inject instance manager directory as global git config home directory
@@ -1635,9 +1654,87 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1635
1654
for stream =errStream ,outStream {
1636
1655
set stream .RemoveOnClose = 1
1637
1656
}
1657
+
1658
+ if syncIris {
1659
+ if diffBase = " " {
1660
+ set diffBase = ..GetCurrentBranch ()
1661
+ }
1662
+ do ..SyncIrisWithRepo (diffBase , diffCompare )
1663
+ }
1638
1664
quit returnCode
1639
1665
}
1640
1666
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
+
1641
1738
ClassMethod GenerateCommitMessageFromFiles (filesWithActions ) As %String
1642
1739
{
1643
1740
set commitMsg = " "
0 commit comments