@@ -1602,9 +1602,10 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
16021602ClassMethod RunGitCommandWithInput (command As %String , inFile As %String = " " , Output errStream , Output outStream , args ...) As %Integer
16031603{
16041604 // Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
1605+ set tempFolder = ..TempFolder ()
16051606 if (command '= " --version" ) {
16061607 set newArgs ($increment (newArgs )) = " -C"
1607- set newArgs ($increment (newArgs )) = .. TempFolder ()
1608+ set newArgs ($increment (newArgs )) = tempFolder
16081609
16091610 set privateKeyFile = ..PrivateKeyFile ()
16101611 if (privateKeyFile '= " " ) {
@@ -1632,34 +1633,90 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16321633 set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
16331634 set diffBase = " "
16341635 set diffCompare = " "
1636+ set invert = 0
1637+ set whichStash = " "
16351638
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" ) {
16371659 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 ) {
16391663 // no-op
16401664 }
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" ) {
16421669 set syncIrisWithCommand = 1
16431670 if $data (args ) && $data (args (args ),diffCompare ) {
16441671 // no-op
16451672 }
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+ }
16461684 }
16471685
1686+ // WebUI prefixes with "color.ui=true" so we need to grab the command
1687+ // from later in the args... array
16481688 for i =1 :1 :$get (args ) {
16491689 if ($data (args (i ))) {
16501690 set newArgs ($increment (newArgs )) = args (i )
16511691 if (args (i ) = " checkout" ) {
16521692 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
16571715 }
16581716 } elseif (args (i ) = " merge" ) || (args (i ) = " rebase" ) || (args (i ) = " pull" ) {
16591717 set syncIrisWithCommand = 1
16601718 set diffCompare = args (i + 1 )
16611719 }
1662-
16631720 }
16641721 }
16651722
@@ -1672,6 +1729,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16721729 if diffBase = " " {
16731730 set diffBase = ..GetCurrentBranch ()
16741731 }
1732+
16751733 do ..RunGitCommand (" fetch" , .errorStream , .outputStream )
16761734 kill errorStream , outputStream
16771735 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
17071765
17081766 if syncIrisWithDiff {
17091767 do ..PrintStreams (errStream , outStream )
1710- $$$ThrowOnError(..SyncIrisWithRepoThroughDiff (.files ))
1768+ $$$ThrowOnError(..SyncIrisWithRepoThroughDiff (.files , . filterToFiles , invert ))
17111769 } elseif syncIrisWithCommand {
17121770 do ..PrintStreams (errStream , outStream )
17131771 $$$ThrowOnError(..SyncIrisWithRepoThroughCommand (.outStream ))
@@ -1772,10 +1830,8 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
17721830 set modification .changeType = " A"
17731831 set modification .internalName = " "
17741832 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 )
17771833 } else {
1778- set modification .internalName = " "
1834+ set modification .internalName = ##class ( SourceControl.Git.Utils ). NameToInternalName ( modification . externalName ,, 0 )
17791835 }
17801836 set files ($increment (files )) = modification
17811837 if verbose {
@@ -1784,18 +1840,34 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
17841840 }
17851841}
17861842
1787- ClassMethod SyncIrisWithRepoThroughDiff (ByRef files ) As %Status
1843+ ClassMethod SyncIrisWithRepoThroughDiff (ByRef files , ByRef filterToFiles , invert As %Boolean = 0 ) As %Status
17881844{
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+
17891861 set key = $order (files (" " ))
17901862 set deletedFiles = " "
17911863 set addedFiles = " "
17921864 while (key '= " " ) {
17931865 set modification = files (key )
1794- if (modification .changeType = " D" ){
1866+ if (modification .changeType = " D" ) {
17951867 if (modification .internalName '= " " ) {
17961868 set deletedFiles = deletedFiles _" ," _modification .internalName
17971869 }
1798- } elseif (modification .changeType = " A" ){
1870+ } elseif (modification .changeType = " A" ) {
17991871 set modification .internalName = ##class (SourceControl.Git.Utils ).NameToInternalName (modification .externalName ,,0 )
18001872 if (modification .internalName '= " " ) {
18011873 set addedFiles = addedFiles _" ," _modification .internalName
0 commit comments