Skip to content

Commit 1fad7a5

Browse files
committed
feat: sync works for web stash operations, discard
Also fixes numerous gremlins around staged/unstage Need to stage before stash, unstage before discard Diff works for staged-under-the-hood and unstaged-under-the-hood files
1 parent 9e1c5ff commit 1fad7a5

File tree

3 files changed

+124
-914
lines changed

3 files changed

+124
-914
lines changed

cls/SourceControl/Git/Utils.cls

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,9 +1602,10 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
16021602
ClassMethod 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,10 +1633,32 @@ 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+
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+
}
16351656

16361657
if (command = "checkout") {
16371658
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) {
16391662
// no-op
16401663
}
16411664
} elseif (command = "restore") {
@@ -1655,19 +1678,25 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16551678
set newArgs($increment(newArgs)) = args(i)
16561679
if (args(i) = "checkout") {
16571680
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+
}
16621688
}
16631689
} 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+
}
16661696
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
16671697
set syncIrisWithCommand = 1
16681698
set diffCompare = args(i + 1)
16691699
}
1670-
16711700
}
16721701
}
16731702

@@ -1680,6 +1709,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16801709
if diffBase = "" {
16811710
set diffBase = ..GetCurrentBranch()
16821711
}
1712+
16831713
do ..RunGitCommand("fetch", .errorStream, .outputStream)
16841714
kill errorStream, outputStream
16851715
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
17151745

17161746
if syncIrisWithDiff {
17171747
do ..PrintStreams(errStream, outStream)
1718-
$$$ThrowOnError(..SyncIrisWithRepoThroughDiff(.files))
1748+
$$$ThrowOnError(..SyncIrisWithRepoThroughDiff(.files, .filterToFiles, invert))
17191749
} elseif syncIrisWithCommand {
17201750
do ..PrintStreams(errStream, outStream)
17211751
$$$ThrowOnError(..SyncIrisWithRepoThroughCommand(.outStream))
@@ -1780,10 +1810,8 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
17801810
set modification.changeType = "A"
17811811
set modification.internalName = ""
17821812
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)
17851813
} else {
1786-
set modification.internalName = ""
1814+
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
17871815
}
17881816
set files($increment(files)) = modification
17891817
if verbose {
@@ -1792,18 +1820,34 @@ ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, O
17921820
}
17931821
}
17941822

1795-
ClassMethod SyncIrisWithRepoThroughDiff(ByRef files) As %Status
1823+
ClassMethod SyncIrisWithRepoThroughDiff(ByRef files, ByRef filterToFiles, invert As %Boolean = 0) As %Status
17961824
{
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+
17971841
set key = $order(files(""))
17981842
set deletedFiles = ""
17991843
set addedFiles = ""
18001844
while (key '= "") {
18011845
set modification = files(key)
1802-
if (modification.changeType = "D"){
1846+
if (modification.changeType = "D") {
18031847
if (modification.internalName '= "") {
18041848
set deletedFiles = deletedFiles_","_modification.internalName
18051849
}
1806-
} elseif (modification.changeType = "A"){
1850+
} elseif (modification.changeType = "A") {
18071851
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
18081852
if (modification.internalName '= "") {
18091853
set addedFiles = addedFiles_","_modification.internalName

0 commit comments

Comments
 (0)