Skip to content

Commit 44dd368

Browse files
authored
Merge pull request #373 from intersystems/sync-iris-codebase-change
Sync with iris for all local repo changes
2 parents 4834974 + fa65394 commit 44dd368

File tree

4 files changed

+124
-82
lines changed

4 files changed

+124
-82
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Now skips files belonging to other git enabled packages in `##class(SourceControl.Git.Change).RefreshUncommitted()` (#347)
1818
- Added a new "Branch" parameter to `##class(SourceControl.Git.PullEventHandler)` (#351)
1919
- Command-line utility to do a baseline export of items in a namespace
20-
- 'New Branch' menu option in basic now will create new branches from the configured default merge branch
21-
- Merging back with the default merge branch is now a part of the basic mode's Sync flow
20+
- 'New Branch' menu option in basic now will create new branches from the configured default merge branch (#366)
21+
- Merging back with the default merge branch is now a part of the basic mode's Sync flow (#366)
2222

2323
### Fixed
24+
- Modifications to local repo files are now synced with IRIS (#153)
2425
- Menu items names are properly translated from internal name in VSCode, Management Portal (#372)
2526

2627
## [2.3.1] - 2024-04-30

cls/SourceControl/Git/API.cls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ ClassMethod Configure()
3737
}
3838

3939
/// API for git pull - just wraps Utils
40-
ClassMethod Pull(preview As %Boolean = 0)
40+
ClassMethod Pull()
4141
{
42-
quit ##class(SourceControl.Git.Utils).Pull(,.preview)
42+
quit ##class(SourceControl.Git.Utils).Pull()
4343
}
4444

4545
/// Locks the environment to prevent changes to code other than through git pull.
@@ -65,3 +65,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
6565
}
6666

6767
}
68+

cls/SourceControl/Git/Utils.cls

Lines changed: 114 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -468,89 +468,17 @@ ClassMethod GetCurrentBranch() As %String
468468
quit branchName
469469
}
470470

471-
ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Status
471+
ClassMethod Pull(remote As %String = "origin") As %Status
472472
{
473473
#define Force 1
474474
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outStream,"--show-current")
475475
set branchName = outStream.ReadLine(outStream.Size)
476476
write !, "Pulling from branch: ", branchName
477-
478-
set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName)
479-
if (sc=1){
480-
do ..PrintStreams(errStream)
481-
quit sc
482-
}
483-
484-
write !, "Fetch done"
485-
write !, "Files that will be modified by git pull: "
486-
487-
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errStream,.outStream, branchName_".."_remote_"/"_branchName, "--name-status")
488-
while (outStream.AtEnd = 0) {
489-
set file = outStream.ReadLine()
490-
set modification = ##class(SourceControl.Git.Modification).%New()
491-
set modification.changeType = $piece(file, $c(9), 1)
492-
set modification.externalName = $zstrip($piece(file, $c(9),2),"<W")
493-
if (modification.changeType '= "A"){
494-
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
495-
}
496-
else {
497-
set modification.internalName = ""
498-
}
499-
set files($increment(files)) = modification
500-
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
501-
}
502-
if ('$data(files)) {
503-
write !, ?4, "None"
504-
if preview {
505-
quit $$$OK
506-
}
507-
write !, "Already up to date."
508-
quit $$$OK
509-
} elseif preview {
510-
quit $$$OK
511-
}
512-
513-
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
514-
if (sc=1){
515-
do ..PrintStreams(errStream, outStream)
516-
quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.")
517-
}
518-
do ..PrintStreams(outStream)
519-
write !
520-
521-
set key = $order(files(""))
522-
set deletedFiles = ""
523-
set addedFiles = ""
524-
while(key '= "") {
525-
set modification = files(key)
526-
if (modification.changeType = "D"){
527-
if (modification.internalName '= "") {
528-
set deletedFiles = deletedFiles_","_modification.internalName
529-
}
530-
} elseif (modification.changeType = "A"){
531-
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
532-
if (modification.internalName '= "") {
533-
set addedFiles = addedFiles_","_modification.internalName
534-
set files(key) = modification
535-
}
536-
}
537-
set key = $order(files(key))
538-
}
539-
540-
set deletedFiles = $extract(deletedFiles, 2, *)
541-
set addedFiles = $extract(addedFiles, 2, *)
477+
kill errStream, outStream
478+
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName)
542479

543-
if (deletedFiles '= ""){
544-
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
545-
}
546-
if (addedFiles '= ""){
547-
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
548-
}
549-
550-
set event = $classmethod(..PullEventClass(),"%New")
551-
set event.LocalRoot = ..TempFolder()
552-
merge event.ModifiedFiles = files
553-
quit event.OnPull()
480+
w !, "Pull ran with return code: " _ returnCode
481+
quit $$$OK
554482
}
555483

556484
ClassMethod Clone(remote As %String) As %Status
@@ -1606,6 +1534,10 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
16061534

16071535
ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer
16081536
{
1537+
set pullArg = ""
1538+
if command = "pull" {
1539+
set pullArg = args(1)
1540+
}
16091541
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
16101542
if (command '= "--version") {
16111543
set newArgs($increment(newArgs)) = "-C"
@@ -1633,16 +1565,76 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16331565

16341566
set newArgs($increment(newArgs)) = command
16351567

1568+
// defining variables for if statement use later
1569+
set syncIris = 0
1570+
set diffBase = ""
1571+
set diffCompare = ""
1572+
set pullOriginIndex = ""
1573+
if (command = "checkout") || (command = "merge") || (command = "rebase") || (command = "pull"){
1574+
set syncIris = 1
1575+
set diffCompare = args(args)
1576+
}
1577+
1578+
16361579
for i=1:1:$get(args) {
16371580
if ($data(args(i))) {
16381581
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
1587+
set diffCompare = args(i + 1)
1588+
1589+
if args = (i + 2) {
1590+
set diffBase = args(i + 2)
1591+
}
1592+
}
1593+
1594+
if (args(i) = "pull") {
1595+
set pullOriginIndex = i
1596+
}
1597+
}
1598+
}
1599+
1600+
if (diffCompare = "--no-commit") || (diffCompare = "--abort") {
1601+
set syncIris = 0
1602+
}
1603+
1604+
if syncIris {
1605+
if diffBase = "" {
1606+
set diffBase = ..GetCurrentBranch()
1607+
}
1608+
do ..RunGitCommand("fetch", .errorStream, .outputStream)
1609+
kill errorStream, outputStream
1610+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_".."_diffCompare, "--name-status")
1611+
while (outputStream.AtEnd = 0) {
1612+
set file = outputStream.ReadLine()
1613+
set modification = ##class(SourceControl.Git.Modification).%New()
1614+
set modification.changeType = $piece(file, $c(9), 1)
1615+
1616+
set modification.externalName = $zstrip($piece(file, $c(9),2),"<W")
1617+
if (modification.changeType '= "A"){
1618+
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
1619+
}
1620+
else {
1621+
set modification.internalName = ""
1622+
}
1623+
set files($increment(files)) = modification
1624+
set mod = files(files)
1625+
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
1626+
}
1627+
1628+
if pullOriginIndex '= "" {
1629+
set newArgs(pullOriginIndex) = $piece(newArgs(pullOriginIndex), "/", 1)
16391630
}
16401631
}
16411632

16421633
set outLog = ##class(%Library.File).TempFilename()
16431634
set errLog = ##class(%Library.File).TempFilename()
16441635

16451636
set command = $extract(..GitBinPath(),2,*-1)
1637+
16461638
set baseArgs = "/STDOUT="_$$$QUOTE(outLog)_" /STDERR="_$$$QUOTE(errLog)_$case(inFile, "":"", :" /STDIN="_$$$QUOTE(inFile))
16471639
try {
16481640
// Inject instance manager directory as global git config home directory
@@ -1664,9 +1656,54 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16641656
for stream=errStream,outStream {
16651657
set stream.RemoveOnClose = 1
16661658
}
1659+
do ..PrintStreams(errStream, outStream)
1660+
if syncIris {
1661+
1662+
$$$ThrowOnError(..SyncIrisWithRepo(.files))
1663+
1664+
}
16671665
quit returnCode
16681666
}
16691667

1668+
ClassMethod SyncIrisWithRepo(ByRef files)
1669+
{
1670+
1671+
set key = $order(files(""))
1672+
set deletedFiles = ""
1673+
set addedFiles = ""
1674+
while(key '= "") {
1675+
set modification = files(key)
1676+
if (modification.changeType = "D"){
1677+
if (modification.internalName '= "") {
1678+
set deletedFiles = deletedFiles_","_modification.internalName
1679+
}
1680+
} elseif (modification.changeType = "A"){
1681+
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
1682+
if (modification.internalName '= "") {
1683+
set addedFiles = addedFiles_","_modification.internalName
1684+
set files(key) = modification
1685+
1686+
}
1687+
}
1688+
set key = $order(files(key))
1689+
}
1690+
1691+
set deletedFiles = $extract(deletedFiles, 2, *)
1692+
set addedFiles = $extract(addedFiles, 2, *)
1693+
1694+
if (deletedFiles '= ""){
1695+
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
1696+
}
1697+
if (addedFiles '= ""){
1698+
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
1699+
}
1700+
1701+
set event = $classmethod(..PullEventClass(),"%New")
1702+
set event.LocalRoot = ..TempFolder()
1703+
merge event.ModifiedFiles = files
1704+
quit event.OnPull()
1705+
}
1706+
16701707
ClassMethod GenerateCommitMessageFromFiles(filesWithActions) As %String
16711708
{
16721709
set commitMsg = ""

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ Property OriginalDevice;
1212
ClassMethod Run()
1313
{
1414
If %request.Get("method") = "preview" {
15-
Do ##class(SourceControl.Git.API).Pull(1)
15+
set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch()
16+
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch")
17+
kill errStream, outStream
18+
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "diff", "origin/"_branchName, "--name-status")
1619
} ElseIf %request.Get("method") = "pull" {
1720
Do ##class(SourceControl.Git.API).Pull()
1821
} ElseIf %request.Get("method") = "init" {

0 commit comments

Comments
 (0)