@@ -1602,9 +1602,10 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
1602
1602
ClassMethod RunGitCommandWithInput (command As %String , inFile As %String = " " , Output errStream , Output outStream , args ...) As %Integer
1603
1603
{
1604
1604
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
1605
+ set tempFolder = ..TempFolder ()
1605
1606
if (command '= " --version" ) {
1606
1607
set newArgs ($increment (newArgs )) = " -C"
1607
- set newArgs ($increment (newArgs )) = .. TempFolder ()
1608
+ set newArgs ($increment (newArgs )) = tempFolder
1608
1609
1609
1610
set privateKeyFile = ..PrivateKeyFile ()
1610
1611
if (privateKeyFile '= " " ) {
@@ -1632,10 +1633,32 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1632
1633
set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
1633
1634
set diffBase = " "
1634
1635
set diffCompare = " "
1636
+ set invert = 0
1637
+
1638
+ // Find / build file list
1639
+ set hasFileList = 0
1640
+ for i =1 :1 :$get (args ) {
1641
+ if $data (args (i ),arg )#2 {
1642
+ if hasFileList {
1643
+ if arg [ tempFolder {
1644
+ set relativeFile = $Piece (arg ,tempFolder ,2 )
1645
+ } else {
1646
+ set relativeFile = arg
1647
+ }
1648
+ if (relativeFile '= " " ) {
1649
+ set filterToFiles (relativeFile ) = " "
1650
+ }
1651
+ } elseif arg = " --" {
1652
+ set hasFileList = 1
1653
+ }
1654
+ }
1655
+ }
1635
1656
1636
1657
if (command = " checkout" ) {
1637
1658
set syncIrisWithDiff = 1
1638
- if $data (args ) && $data (args (args ),diffCompare ) {
1659
+ if hasFileList {
1660
+ set invert = 1
1661
+ } elseif $data (args ) && $data (args (args ),diffCompare ) {
1639
1662
// no-op
1640
1663
}
1641
1664
} elseif (command = " restore" ) {
@@ -1655,19 +1678,25 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1655
1678
set newArgs ($increment (newArgs )) = args (i )
1656
1679
if (args (i ) = " checkout" ) {
1657
1680
set syncIrisWithDiff = 1
1658
- set diffCompare = args (i + 1 )
1659
-
1660
- if args = (i + 2 ) {
1661
- set diffBase = args (i + 2 )
1681
+ if hasFileList {
1682
+ set invert = 1
1683
+ } else {
1684
+ set diffCompare = args (i + 1 )
1685
+ if args = (i + 2 ) {
1686
+ set diffBase = args (i + 2 )
1687
+ }
1662
1688
}
1663
1689
} elseif (args (i ) = " restore" ) || (args (i ) = " stash" ) {
1664
- set syncIrisWithDiff = 1
1665
- set diffCompare = " "
1690
+ // stash list shouldn't trigger anything
1691
+ if ($Get (args (i + 1 )) '= " list" ) {
1692
+ set syncIrisWithDiff = 1
1693
+ set diffCompare = " "
1694
+ set invert = 1
1695
+ }
1666
1696
} elseif (args (i ) = " merge" ) || (args (i ) = " rebase" ) || (args (i ) = " pull" ) {
1667
1697
set syncIrisWithCommand = 1
1668
1698
set diffCompare = args (i + 1 )
1669
1699
}
1670
-
1671
1700
}
1672
1701
}
1673
1702
@@ -1680,6 +1709,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1680
1709
if diffBase = " " {
1681
1710
set diffBase = ..GetCurrentBranch ()
1682
1711
}
1712
+
1683
1713
do ..RunGitCommand (" fetch" , .errorStream , .outputStream )
1684
1714
kill errorStream , outputStream
1685
1715
do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errorStream ,.outputStream , diffBase _$Case (diffCompare ," " :" " ,:" .." )_diffCompare , " --name-status" )
@@ -1715,7 +1745,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1715
1745
1716
1746
if syncIrisWithDiff {
1717
1747
do ..PrintStreams (errStream , outStream )
1718
- $$$ThrowOnError(..SyncIrisWithRepoThroughDiff (.files ))
1748
+ $$$ThrowOnError(..SyncIrisWithRepoThroughDiff (.files , . filterToFiles , invert ))
1719
1749
} elseif syncIrisWithCommand {
1720
1750
do ..PrintStreams (errStream , outStream )
1721
1751
$$$ThrowOnError(..SyncIrisWithRepoThroughCommand (.outStream ))
@@ -1780,10 +1810,8 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
1780
1810
set modification .changeType = " A"
1781
1811
set modification .internalName = " "
1782
1812
set modification .externalName = $zstrip ($piece (file , $c (9 ), 3 )," <W" )
1783
- } elseif (modification .changeType '= " A" ){
1784
- set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
1785
1813
} else {
1786
- set modification .internalName = " "
1814
+ set modification .internalName = ##class ( SourceControl.Git.Utils ). NameToInternalName ( modification . externalName ,, 0 )
1787
1815
}
1788
1816
set files ($increment (files )) = modification
1789
1817
if verbose {
@@ -1792,18 +1820,34 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
1792
1820
}
1793
1821
}
1794
1822
1795
- ClassMethod SyncIrisWithRepoThroughDiff (ByRef files ) As %Status
1823
+ ClassMethod SyncIrisWithRepoThroughDiff (ByRef files , ByRef filterToFiles , invert As %Boolean = 0 ) As %Status
1796
1824
{
1825
+ if invert {
1826
+ // Change A <-> D
1827
+ set key = " "
1828
+ for {
1829
+ set key = $order (files (key ),1 ,modification )
1830
+ quit :key =" "
1831
+ if '$data (filterToFiles (modification .externalName )) {
1832
+ continue
1833
+ }
1834
+ set modification .changeType = $translate (modification .changeType ," DA" ," AD" )
1835
+ set realFiles ($increment (realFiles )) = modification
1836
+ }
1837
+ kill files
1838
+ merge files = realFiles
1839
+ }
1840
+
1797
1841
set key = $order (files (" " ))
1798
1842
set deletedFiles = " "
1799
1843
set addedFiles = " "
1800
1844
while (key '= " " ) {
1801
1845
set modification = files (key )
1802
- if (modification .changeType = " D" ){
1846
+ if (modification .changeType = " D" ) {
1803
1847
if (modification .internalName '= " " ) {
1804
1848
set deletedFiles = deletedFiles _" ," _modification .internalName
1805
1849
}
1806
- } elseif (modification .changeType = " A" ){
1850
+ } elseif (modification .changeType = " A" ) {
1807
1851
set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
1808
1852
if (modification .internalName '= " " ) {
1809
1853
set addedFiles = addedFiles _" ," _modification .internalName
0 commit comments