Skip to content

Commit 61a58db

Browse files
authored
Merge pull request #384 from intersystems/merge-rebase-resolve-diff-issue
Merge, Pull and Rebase now don't use diff to synchronize file system with IRIS
2 parents 6f39ea8 + 4fd138a commit 61a58db

File tree

4 files changed

+70
-29
lines changed

4 files changed

+70
-29
lines changed

cls/SourceControl/Git/Util/Buffer.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,4 @@ Method UsePreviousDeviceAndSettings() [ Internal, Private ]
281281
}
282282

283283
}
284+

cls/SourceControl/Git/Utils.cls

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ ClassMethod Pull(remote As %String = "origin") As %Status
475475
set branchName = outStream.ReadLine(outStream.Size)
476476
write !, "Pulling from branch: ", branchName
477477
kill errStream, outStream
478-
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName)
478+
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote)
479479

480480
w !, "Pull ran with return code: " _ returnCode
481481
quit $$$OK
@@ -1534,10 +1534,6 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
15341534

15351535
ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer
15361536
{
1537-
set pullArg = ""
1538-
if command = "pull" {
1539-
set pullArg = args(1)
1540-
}
15411537
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
15421538
if (command '= "--version") {
15431539
set newArgs($increment(newArgs)) = "-C"
@@ -1565,43 +1561,44 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
15651561

15661562
set newArgs($increment(newArgs)) = command
15671563

1568-
// defining variables for if statement use later
1569-
set syncIris = 0
1564+
set syncIrisWithDiff = 0 // whether IRIS needs to be synced with repo file changes using diff output
1565+
set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
15701566
set diffBase = ""
15711567
set diffCompare = ""
1572-
set pullOriginIndex = ""
1573-
if (command = "checkout") || (command = "merge") || (command = "rebase") || (command = "pull"){
1574-
set syncIris = 1
1568+
1569+
if (command = "checkout"){
1570+
set syncIrisWithDiff = 1
1571+
set diffCompare = args(args)
1572+
} elseif (command = "merge") || (command = "rebase") || (command = "pull"){
1573+
set syncIrisWithCommand = 1
15751574
set diffCompare = args(args)
15761575
}
15771576

15781577

15791578
for i=1:1:$get(args) {
15801579
if ($data(args(i))) {
15811580
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
1581+
if (args(i) = "checkout") {
1582+
set syncIrisWithDiff = 1
15871583
set diffCompare = args(i + 1)
15881584

15891585
if args = (i + 2) {
15901586
set diffBase = args(i + 2)
15911587
}
1588+
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
1589+
set syncIrisWithCommand = 1
1590+
set diffCompare = args(i + 1)
15921591
}
15931592

1594-
if (args(i) = "pull") {
1595-
set pullOriginIndex = i
1596-
}
15971593
}
15981594
}
15991595

1600-
if (diffCompare = "--no-commit") || (diffCompare = "--abort") {
1601-
set syncIris = 0
1596+
if (diffCompare = "--no-commit") || (diffCompare = "--abort") || (diffCompare = "-b") {
1597+
set syncIrisWithDiff = 0
1598+
set syncIrisWithCommand = 0
16021599
}
16031600

1604-
if syncIris {
1601+
if syncIrisWithDiff {
16051602
if diffBase = "" {
16061603
set diffBase = ..GetCurrentBranch()
16071604
}
@@ -1621,13 +1618,9 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16211618
set modification.internalName = ""
16221619
}
16231620
set files($increment(files)) = modification
1624-
set mod = files(files)
16251621
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
16261622
}
16271623

1628-
if pullOriginIndex '= "" {
1629-
set newArgs(pullOriginIndex) = $piece(newArgs(pullOriginIndex), "/", 1)
1630-
}
16311624
}
16321625

16331626
set outLog = ##class(%Library.File).TempFilename()
@@ -1657,15 +1650,60 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16571650
set stream.RemoveOnClose = 1
16581651
}
16591652
do ..PrintStreams(errStream, outStream)
1660-
if syncIris {
1661-
$$$ThrowOnError(..SyncIrisWithRepo(.files))
1653+
if syncIrisWithDiff {
1654+
$$$ThrowOnError(..SyncIrisWithRepoThroughDiff(.files))
1655+
} elseif syncIrisWithCommand {
1656+
$$$ThrowOnError(..SyncIrisWithRepoThroughCommand(.outStream))
16621657
}
16631658
quit returnCode
16641659
}
16651660

1666-
ClassMethod SyncIrisWithRepo(ByRef files)
1661+
ClassMethod SyncIrisWithRepoThroughCommand(ByRef outStream) As %Status
16671662
{
1663+
set deletedFiles = ""
1664+
set addedFiles = ""
1665+
set files = ""
1666+
while (outStream.AtEnd = 0) {
1667+
1668+
set line = outStream.ReadLine()
1669+
set lineStart = $piece(line, " ", 2)
1670+
if (lineStart = "delete") || (lineStart = "create") {
1671+
set fileOperation = $select(lineStart = "create" : "A", 1: "D")
1672+
set externalName = $piece(line, " ", *)
1673+
set internalName = ##class(SourceControl.Git.Utils).NameToInternalName(externalName,,0)
1674+
set modification = ##class(SourceControl.Git.Modification).%New()
1675+
set modification.changeType = fileOperation
1676+
set modification.internalName = internalName
1677+
set modification.externalName = externalName
1678+
set files($i(files)) = modification
1679+
if fileOperation = "A" {
1680+
set addedFiles = addedFiles_","_internalName
1681+
} else {
1682+
set deletedFiles = deletedFiles_","_internalName
1683+
}
1684+
}
1685+
}
1686+
1687+
set deletedFiles = $extract(deletedFiles, 2, *)
1688+
set addedFiles = $extract(addedFiles, 2, *)
1689+
1690+
1691+
if (deletedFiles '= ""){
1692+
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
1693+
}
1694+
if (addedFiles '= ""){
1695+
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
1696+
}
16681697

1698+
do outStream.Rewind()
1699+
set event = $classmethod(..PullEventClass(),"%New")
1700+
set event.LocalRoot = ..TempFolder()
1701+
merge event.ModifiedFiles = files
1702+
quit event.OnPull()
1703+
}
1704+
1705+
ClassMethod SyncIrisWithRepoThroughDiff(ByRef files) As %Status
1706+
{
16691707
set key = $order(files(""))
16701708
set deletedFiles = ""
16711709
set addedFiles = ""
@@ -2348,3 +2386,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
23482386
}
23492387

23502388
}
2389+

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,4 @@ ClassMethod GetPackageVersion() As %Library.DynamicObject
243243
}
244244

245245
}
246+

cls/_zpkg/isc/sc/git/Socket.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ClassMethod Run()
1515
set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch()
1616
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch")
1717
kill errStream, outStream
18-
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "diff", "origin/"_branchName, "--name-status")
18+
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "log", "HEAD..origin", "--name-status")
1919
} ElseIf %request.Get("method") = "pull" {
2020
Do ##class(SourceControl.Git.API).Pull()
2121
} ElseIf %request.Get("method") = "init" {

0 commit comments

Comments
 (0)