@@ -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,34 +1633,90 @@ 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
+ set whichStash = " "
1635
1638
1636
- if (command = " checkout" ){
1639
+ // Find / build file list
1640
+ set hasFileList = 0
1641
+ for i =1 :1 :$get (args ) {
1642
+ if $data (args (i ),arg )#2 {
1643
+ if hasFileList {
1644
+ if arg [ tempFolder {
1645
+ set relativeFile = $Piece (arg ,tempFolder ,2 )
1646
+ } else {
1647
+ set relativeFile = arg
1648
+ }
1649
+ if (relativeFile '= " " ) {
1650
+ set filterToFiles (relativeFile ) = " "
1651
+ }
1652
+ } elseif arg = " --" {
1653
+ set hasFileList = 1
1654
+ }
1655
+ }
1656
+ }
1657
+
1658
+ if (command = " checkout" ) {
1637
1659
set syncIrisWithDiff = 1
1638
- if $data (args ) && $data (args (args ),diffCompare ) {
1660
+ if hasFileList {
1661
+ set invert = 1
1662
+ } elseif $data (args ) && $data (args (args ),diffCompare ) {
1639
1663
// no-op
1640
1664
}
1641
- } elseif (command = " merge" ) || (command = " rebase" ) || (command = " pull" ){
1665
+ } elseif (command = " restore" ) {
1666
+ // Leave diffCompare empty, this actually does the right thing.
1667
+ set syncIrisWithDiff = 1
1668
+ } elseif (command = " merge" ) || (command = " rebase" ) || (command = " pull" ) {
1642
1669
set syncIrisWithCommand = 1
1643
1670
if $data (args ) && $data (args (args ),diffCompare ) {
1644
1671
// no-op
1645
1672
}
1673
+ } elseif (command = " stash" ) {
1674
+ set subcommand = $Get (args (1 ))
1675
+ set whichStash = $Get (args (2 ))
1676
+ if subcommand = " push" {
1677
+ set syncIrisWithDiff = 1
1678
+ set diffCompare = " "
1679
+ set invert = 1
1680
+ } elseif (subcommand = " pop" ) || (subcommand = " apply" ) {
1681
+ set syncIrisWithDiff = 1
1682
+ set diffCompare = whichStash
1683
+ }
1646
1684
}
1647
1685
1686
+ // WebUI prefixes with "color.ui=true" so we need to grab the command
1687
+ // from later in the args... array
1648
1688
for i =1 :1 :$get (args ) {
1649
1689
if ($data (args (i ))) {
1650
1690
set newArgs ($increment (newArgs )) = args (i )
1651
1691
if (args (i ) = " checkout" ) {
1652
1692
set syncIrisWithDiff = 1
1653
- set diffCompare = args (i + 1 )
1654
-
1655
- if args = (i + 2 ) {
1656
- set diffBase = args (i + 2 )
1693
+ if hasFileList {
1694
+ set invert = 1
1695
+ } else {
1696
+ set diffCompare = args (i + 1 )
1697
+ if args = (i + 2 ) {
1698
+ set diffBase = args (i + 2 )
1699
+ }
1700
+ }
1701
+ } elseif (args (i ) = " restore" ) {
1702
+ set syncIrisWithDiff = 1
1703
+ set diffCompare = " "
1704
+ set invert = 1
1705
+ } elseif (args (i ) = " stash" ) {
1706
+ set subcommand = $Get (args (i + 1 ))
1707
+ set whichStash = $Get (args (i + 2 ))
1708
+ if subcommand = " push" {
1709
+ set syncIrisWithDiff = 1
1710
+ set diffCompare = " "
1711
+ set invert = 1
1712
+ } elseif (subcommand = " pop" ) || (subcommand = " apply" ) {
1713
+ set syncIrisWithDiff = 1
1714
+ set diffCompare = whichStash
1657
1715
}
1658
1716
} elseif (args (i ) = " merge" ) || (args (i ) = " rebase" ) || (args (i ) = " pull" ) {
1659
1717
set syncIrisWithCommand = 1
1660
1718
set diffCompare = args (i + 1 )
1661
1719
}
1662
-
1663
1720
}
1664
1721
}
1665
1722
@@ -1672,6 +1729,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1672
1729
if diffBase = " " {
1673
1730
set diffBase = ..GetCurrentBranch ()
1674
1731
}
1732
+
1675
1733
do ..RunGitCommand (" fetch" , .errorStream , .outputStream )
1676
1734
kill errorStream , outputStream
1677
1735
do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errorStream ,.outputStream , diffBase _$Case (diffCompare ," " :" " ,:" .." )_diffCompare , " --name-status" )
@@ -1707,7 +1765,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1707
1765
1708
1766
if syncIrisWithDiff {
1709
1767
do ..PrintStreams (errStream , outStream )
1710
- $$$ThrowOnError(..SyncIrisWithRepoThroughDiff (.files ))
1768
+ $$$ThrowOnError(..SyncIrisWithRepoThroughDiff (.files , . filterToFiles , invert ))
1711
1769
} elseif syncIrisWithCommand {
1712
1770
do ..PrintStreams (errStream , outStream )
1713
1771
$$$ThrowOnError(..SyncIrisWithRepoThroughCommand (.outStream ))
@@ -1772,10 +1830,8 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
1772
1830
set modification .changeType = " A"
1773
1831
set modification .internalName = " "
1774
1832
set modification .externalName = $zstrip ($piece (file , $c (9 ), 3 )," <W" )
1775
- } elseif (modification .changeType '= " A" ){
1776
- set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
1777
1833
} else {
1778
- set modification .internalName = " "
1834
+ set modification .internalName = ##class ( SourceControl.Git.Utils ). NameToInternalName ( modification . externalName ,, 0 )
1779
1835
}
1780
1836
set files ($increment (files )) = modification
1781
1837
if verbose {
@@ -1784,18 +1840,34 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
1784
1840
}
1785
1841
}
1786
1842
1787
- ClassMethod SyncIrisWithRepoThroughDiff (ByRef files ) As %Status
1843
+ ClassMethod SyncIrisWithRepoThroughDiff (ByRef files , ByRef filterToFiles , invert As %Boolean = 0 ) As %Status
1788
1844
{
1845
+ if invert {
1846
+ // Change A <-> D
1847
+ set key = " "
1848
+ for {
1849
+ set key = $order (files (key ),1 ,modification )
1850
+ quit :key =" "
1851
+ if '$data (filterToFiles (modification .externalName )) {
1852
+ continue
1853
+ }
1854
+ set modification .changeType = $translate (modification .changeType ," DA" ," AD" )
1855
+ set realFiles ($increment (realFiles )) = modification
1856
+ }
1857
+ kill files
1858
+ merge files = realFiles
1859
+ }
1860
+
1789
1861
set key = $order (files (" " ))
1790
1862
set deletedFiles = " "
1791
1863
set addedFiles = " "
1792
1864
while (key '= " " ) {
1793
1865
set modification = files (key )
1794
- if (modification .changeType = " D" ){
1866
+ if (modification .changeType = " D" ) {
1795
1867
if (modification .internalName '= " " ) {
1796
1868
set deletedFiles = deletedFiles _" ," _modification .internalName
1797
1869
}
1798
- } elseif (modification .changeType = " A" ){
1870
+ } elseif (modification .changeType = " A" ) {
1799
1871
set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
1800
1872
if (modification .internalName '= " " ) {
1801
1873
set addedFiles = addedFiles _" ," _modification .internalName
0 commit comments