@@ -468,89 +468,17 @@ ClassMethod GetCurrentBranch() As %String
468
468
quit branchName
469
469
}
470
470
471
- ClassMethod Pull (remote As %String = " origin" , preview As %Boolean = 0 ) As %Status
471
+ ClassMethod Pull (remote As %String = " origin" ) As %Status
472
472
{
473
473
#define Force 1
474
474
do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" branch" ,,.errStream ,.outStream ," --show-current" )
475
475
set branchName = outStream .ReadLine (outStream .Size )
476
476
write !, " Pulling from branch: " , branchName
477
-
478
- set sc = ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" fetch" ,,.errStream ,.outStream , remote , branchName )
479
- if (sc =1 ){
480
- do ..PrintStreams (errStream )
481
- quit sc
482
- }
483
-
484
- write !, " Fetch done"
485
- write !, " Files that will be modified by git pull: "
486
-
487
- do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errStream ,.outStream , branchName _" .." _remote _" /" _branchName , " --name-status" )
488
- while (outStream .AtEnd = 0 ) {
489
- set file = outStream .ReadLine ()
490
- set modification = ##class (SourceControl.Git.Modification ).%New ()
491
- set modification .changeType = $piece (file , $c (9 ), 1 )
492
- set modification .externalName = $zstrip ($piece (file , $c (9 ),2 )," <W" )
493
- if (modification .changeType '= " A" ){
494
- set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
495
- }
496
- else {
497
- set modification .internalName = " "
498
- }
499
- set files ($increment (files )) = modification
500
- write !, ?4 , modification .changeType , ?4 , modification .internalName , ?4 , modification .externalName
501
- }
502
- if ('$data (files )) {
503
- write !, ?4 , " None"
504
- if preview {
505
- quit $$$OK
506
- }
507
- write !, " Already up to date."
508
- quit $$$OK
509
- } elseif preview {
510
- quit $$$OK
511
- }
512
-
513
- set sc = ..RunGitWithArgs (.errStream , .outStream , " pull" , remote , branchName )
514
- if (sc =1 ){
515
- do ..PrintStreams (errStream , outStream )
516
- quit $$$ERROR(5001 , " Pull event handler not called. Fix errors before compiling." )
517
- }
518
- do ..PrintStreams (outStream )
519
- write !
520
-
521
- set key = $order (files (" " ))
522
- set deletedFiles = " "
523
- set addedFiles = " "
524
- while (key '= " " ) {
525
- set modification = files (key )
526
- if (modification .changeType = " D" ){
527
- if (modification .internalName '= " " ) {
528
- set deletedFiles = deletedFiles _" ," _modification .internalName
529
- }
530
- } elseif (modification .changeType = " A" ){
531
- set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
532
- if (modification .internalName '= " " ) {
533
- set addedFiles = addedFiles _" ," _modification .internalName
534
- set files (key ) = modification
535
- }
536
- }
537
- set key = $order (files (key ))
538
- }
539
-
540
- set deletedFiles = $extract (deletedFiles , 2 , *)
541
- set addedFiles = $extract (addedFiles , 2 , *)
477
+ kill errStream , outStream
478
+ set returnCode = ..RunGitWithArgs (.errStream , .outStream , " pull" , remote _ " /" _ branchName )
542
479
543
- if (deletedFiles '= " " ){
544
- set sc = ##class (SourceControl.Git.Utils ).RemoveFromServerSideSourceControl (deletedFiles )
545
- }
546
- if (addedFiles '= " " ){
547
- set sc = ##class (SourceControl.Git.Utils ).AddToServerSideSourceControl (addedFiles )
548
- }
549
-
550
- set event = $classmethod (..PullEventClass ()," %New" )
551
- set event .LocalRoot = ..TempFolder ()
552
- merge event .ModifiedFiles = files
553
- quit event .OnPull ()
480
+ w !, " Pull ran with return code: " _ returnCode
481
+ quit $$$OK
554
482
}
555
483
556
484
ClassMethod Clone (remote As %String ) As %Status
@@ -1606,6 +1534,10 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
1606
1534
1607
1535
ClassMethod RunGitCommandWithInput (command As %String , inFile As %String = " " , Output errStream , Output outStream , args ...) As %Integer
1608
1536
{
1537
+ set pullArg = " "
1538
+ if command = " pull" {
1539
+ set pullArg = args (1 )
1540
+ }
1609
1541
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
1610
1542
if (command '= " --version" ) {
1611
1543
set newArgs ($increment (newArgs )) = " -C"
@@ -1633,16 +1565,76 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1633
1565
1634
1566
set newArgs ($increment (newArgs )) = command
1635
1567
1568
+ // defining variables for if statement use later
1569
+ set syncIris = 0
1570
+ set diffBase = " "
1571
+ set diffCompare = " "
1572
+ set pullOriginIndex = " "
1573
+ if (command = " checkout" ) || (command = " merge" ) || (command = " rebase" ) || (command = " pull" ){
1574
+ set syncIris = 1
1575
+ set diffCompare = args (args )
1576
+ }
1577
+
1578
+
1636
1579
for i =1 :1 :$get (args ) {
1637
1580
if ($data (args (i ))) {
1638
1581
set newArgs ($increment (newArgs )) = args (i )
1582
+ if newArgs (newArgs ) = pullArg {
1583
+ set pullOriginIndex = newArgs
1584
+ }
1585
+ if (args (i ) = " checkout" ) || (args (i ) = " merge" ) || (args (i ) = " rebase" ) || (args (i ) = " pull" ){
1586
+ set syncIris = 1
1587
+ set diffCompare = args (i + 1 )
1588
+
1589
+ if args = (i + 2 ) {
1590
+ set diffBase = args (i + 2 )
1591
+ }
1592
+ }
1593
+
1594
+ if (args (i ) = " pull" ) {
1595
+ set pullOriginIndex = i
1596
+ }
1597
+ }
1598
+ }
1599
+
1600
+ if (diffCompare = " --no-commit" ) || (diffCompare = " --abort" ) {
1601
+ set syncIris = 0
1602
+ }
1603
+
1604
+ if syncIris {
1605
+ if diffBase = " " {
1606
+ set diffBase = ..GetCurrentBranch ()
1607
+ }
1608
+ do ..RunGitCommand (" fetch" , .errorStream , .outputStream )
1609
+ kill errorStream , outputStream
1610
+ do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errorStream ,.outputStream , diffBase _" .." _diffCompare , " --name-status" )
1611
+ while (outputStream .AtEnd = 0 ) {
1612
+ set file = outputStream .ReadLine ()
1613
+ set modification = ##class (SourceControl.Git.Modification ).%New ()
1614
+ set modification .changeType = $piece (file , $c (9 ), 1 )
1615
+
1616
+ set modification .externalName = $zstrip ($piece (file , $c (9 ),2 )," <W" )
1617
+ if (modification .changeType '= " A" ){
1618
+ set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
1619
+ }
1620
+ else {
1621
+ set modification .internalName = " "
1622
+ }
1623
+ set files ($increment (files )) = modification
1624
+ set mod = files (files )
1625
+ write !, ?4 , modification .changeType , ?4 , modification .internalName , ?4 , modification .externalName
1626
+ }
1627
+
1628
+ if pullOriginIndex '= " " {
1629
+ set newArgs (pullOriginIndex ) = $piece (newArgs (pullOriginIndex ), " /" , 1 )
1639
1630
}
1640
1631
}
1641
1632
1642
1633
set outLog = ##class (%Library.File ).TempFilename ()
1643
1634
set errLog = ##class (%Library.File ).TempFilename ()
1644
1635
1645
1636
set command = $extract (..GitBinPath (),2 ,*-1 )
1637
+
1646
1638
set baseArgs = " /STDOUT=" _$$$QUOTE(outLog )_" /STDERR=" _$$$QUOTE(errLog )_$case (inFile , " " :" " , :" /STDIN=" _$$$QUOTE(inFile ))
1647
1639
try {
1648
1640
// Inject instance manager directory as global git config home directory
@@ -1664,9 +1656,54 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1664
1656
for stream =errStream ,outStream {
1665
1657
set stream .RemoveOnClose = 1
1666
1658
}
1659
+ do ..PrintStreams (errStream , outStream )
1660
+ if syncIris {
1661
+
1662
+ $$$ThrowOnError(..SyncIrisWithRepo (.files ))
1663
+
1664
+ }
1667
1665
quit returnCode
1668
1666
}
1669
1667
1668
+ ClassMethod SyncIrisWithRepo (ByRef files )
1669
+ {
1670
+
1671
+ set key = $order (files (" " ))
1672
+ set deletedFiles = " "
1673
+ set addedFiles = " "
1674
+ while (key '= " " ) {
1675
+ set modification = files (key )
1676
+ if (modification .changeType = " D" ){
1677
+ if (modification .internalName '= " " ) {
1678
+ set deletedFiles = deletedFiles _" ," _modification .internalName
1679
+ }
1680
+ } elseif (modification .changeType = " A" ){
1681
+ set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
1682
+ if (modification .internalName '= " " ) {
1683
+ set addedFiles = addedFiles _" ," _modification .internalName
1684
+ set files (key ) = modification
1685
+
1686
+ }
1687
+ }
1688
+ set key = $order (files (key ))
1689
+ }
1690
+
1691
+ set deletedFiles = $extract (deletedFiles , 2 , *)
1692
+ set addedFiles = $extract (addedFiles , 2 , *)
1693
+
1694
+ if (deletedFiles '= " " ){
1695
+ set sc = ##class (SourceControl.Git.Utils ).RemoveFromServerSideSourceControl (deletedFiles )
1696
+ }
1697
+ if (addedFiles '= " " ){
1698
+ set sc = ##class (SourceControl.Git.Utils ).AddToServerSideSourceControl (addedFiles )
1699
+ }
1700
+
1701
+ set event = $classmethod (..PullEventClass ()," %New" )
1702
+ set event .LocalRoot = ..TempFolder ()
1703
+ merge event .ModifiedFiles = files
1704
+ quit event .OnPull ()
1705
+ }
1706
+
1670
1707
ClassMethod GenerateCommitMessageFromFiles (filesWithActions ) As %String
1671
1708
{
1672
1709
set commitMsg = " "
0 commit comments