Skip to content

Commit d0c3a5e

Browse files
committed
added fetch before diff, removed redundant code in Pull()
1 parent 7db9617 commit d0c3a5e

File tree

1 file changed

+4
-78
lines changed

1 file changed

+4
-78
lines changed

cls/SourceControl/Git/Utils.cls

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -446,82 +446,8 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat
446446
set branchName = outStream.ReadLine(outStream.Size)
447447
write !, "Pulling from branch: ", branchName
448448

449-
set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName)
450-
if (sc=1){
451-
do ..PrintStreams(errStream)
452-
quit sc
453-
}
454-
455-
write !, "Fetch done"
456-
write !, "Files that will be modified by git pull: "
457-
458-
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errStream,.outStream, branchName_".."_remote_"/"_branchName, "--name-status")
459-
while (outStream.AtEnd = 0) {
460-
set file = outStream.ReadLine()
461-
set modification = ##class(SourceControl.Git.Modification).%New()
462-
set modification.changeType = $piece(file, $c(9), 1)
463-
set modification.externalName = $zstrip($piece(file, $c(9),2),"<W")
464-
if (modification.changeType '= "A"){
465-
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
466-
}
467-
else {
468-
set modification.internalName = ""
469-
}
470-
set files($increment(files)) = modification
471-
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
472-
}
473-
if ('$data(files)) {
474-
write !, ?4, "None"
475-
if preview {
476-
quit $$$OK
477-
}
478-
write !, "Already up to date."
479-
quit $$$OK
480-
} elseif preview {
481-
quit $$$OK
482-
}
483-
484449
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
485-
if (sc=1){
486-
do ..PrintStreams(errStream, outStream)
487-
quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.")
488-
}
489-
do ..PrintStreams(outStream)
490-
write !
491450

492-
set key = $order(files(""))
493-
set deletedFiles = ""
494-
set addedFiles = ""
495-
while(key '= "") {
496-
set modification = files(key)
497-
if (modification.changeType = "D"){
498-
if (modification.internalName '= "") {
499-
set deletedFiles = deletedFiles_","_modification.internalName
500-
}
501-
} elseif (modification.changeType = "A"){
502-
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
503-
if (modification.internalName '= "") {
504-
set addedFiles = addedFiles_","_modification.internalName
505-
set files(key) = modification
506-
}
507-
}
508-
set key = $order(files(key))
509-
}
510-
511-
set deletedFiles = $extract(deletedFiles, 2, *)
512-
set addedFiles = $extract(addedFiles, 2, *)
513-
514-
if (deletedFiles '= ""){
515-
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
516-
}
517-
if (addedFiles '= ""){
518-
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
519-
}
520-
521-
set event = $classmethod(..PullEventClass(),"%New")
522-
set event.LocalRoot = ..TempFolder()
523-
merge event.ModifiedFiles = files
524-
quit event.OnPull()
525451
}
526452

527453
ClassMethod Clone(remote As %String) As %Status
@@ -1609,7 +1535,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16091535
set syncIris = 0
16101536
set diffBase = ""
16111537
set diffCompare = ""
1612-
if (command = "checkout") || (command = "merge") || (command = "rebase") {
1538+
if (command = "checkout") || (command = "merge") || (command = "rebase") || (command = "pull"){
16131539
set syncIris = 1
16141540
set diffCompare = args(args)
16151541
}
@@ -1618,7 +1544,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16181544
for i=1:1:$get(args) {
16191545
if ($data(args(i))) {
16201546
set newArgs($increment(newArgs)) = args(i)
1621-
if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") {
1547+
if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull"){
16221548
set syncIris = 1
16231549
set diffCompare = args(i + 1)
16241550

@@ -1634,11 +1560,11 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16341560
}
16351561

16361562
if syncIris {
1637-
set ^mtemphw("diffc", $i(^mtemphw("diffc"))) = diffCompare
16381563
if diffBase = "" {
16391564
set diffBase = ..GetCurrentBranch()
16401565
}
1641-
set ^mtemphw("diffb", $i(^mtemphw("diffb"))) = diffBase
1566+
do ..RunGitCommand("fetch", .errorStream, .outputStream)
1567+
kill errorStream, outputStream
16421568
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_".."_diffCompare, "--name-status")
16431569
while (outputStream.AtEnd = 0) {
16441570
set file = outputStream.ReadLine()

0 commit comments

Comments
 (0)