Skip to content

Commit c82de15

Browse files
committed
fix: menu discard calls PullEventHandler
refactor: add and use utility methods in PullEventHandler
1 parent 257ab0c commit c82de15

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

cls/SourceControl/Git/PullEventHandler.cls

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,28 @@ Method OnPull() As %Status [ Abstract ]
2020
{
2121
}
2222

23+
/// <var>files</var> is an integer-subscripted array of <class>SourceControl.Git.Modification</class> objects.
24+
ClassMethod ForModifications(ByRef files) As %Status
25+
{
26+
set event = $classmethod(##class(SourceControl.Git.Utils).PullEventClass(),"%New")
27+
set event.LocalRoot = ##class(SourceControl.Git.Utils).TempFolder()
28+
merge event.ModifiedFiles = files
29+
quit event.OnPull()
2330
}
2431

32+
/// <var>InternalName</var> may be a comma-delimited string or $ListBuild list
33+
ClassMethod ForInternalNames(InternalName As %String) As %Status
34+
{
35+
set list = $select($listvalid(InternalName):InternalName,1:$ListFromString(InternalName))
36+
set pointer = 0
37+
while $listnext(list,pointer,InternalName) {
38+
set mod = ##class(SourceControl.Git.Modification).%New()
39+
set mod.internalName = InternalName
40+
set mod.externalName = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
41+
set mod.changeType = "M"
42+
set files($i(files)) = mod
43+
}
44+
quit ..ForModifications(.files)
45+
}
46+
47+
}

cls/SourceControl/Git/Utils.cls

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ ClassMethod Revert(InternalName As %String) As %Status
338338
do ..RunGitCommand("checkout", .errStream, .outStream, "--", filename)
339339
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename,0,1))
340340
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted(0,1,,1))
341-
$$$QuitOnError(..ImportItem(InternalName,1))
342-
quit $$$OK
341+
quit ##class(SourceControl.Git.PullEventHandler).ForInternalNames(InternalName)
343342
}
344343

345344
ClassMethod Commit(InternalName As %String, Message As %String = "example commit message") As %Status
@@ -1415,10 +1414,7 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
14151414
}
14161415
}
14171416

1418-
set eventHandler = $classmethod(..PullEventClass(),"%New")
1419-
set eventHandler.LocalRoot = ..TempFolder()
1420-
merge eventHandler.ModifiedFiles = files
1421-
set sc = eventHandler.OnPull()
1417+
set sc = ##class(SourceControl.Git.PullEventHandler).ForModifications(.files)
14221418
if $$$ISERR(sc) {
14231419
set ec = $$$ADDSC(ec,sc)
14241420
}
@@ -1772,10 +1768,7 @@ ClassMethod SyncIrisWithRepoThroughCommand(ByRef outStream) As %Status
17721768
}
17731769

17741770
do outStream.Rewind()
1775-
set event = $classmethod(..PullEventClass(),"%New")
1776-
set event.LocalRoot = ..TempFolder()
1777-
merge event.ModifiedFiles = files
1778-
quit event.OnPull()
1771+
quit ##class(SourceControl.Git.PullEventHandler).ForModifications(.files)
17791772
}
17801773

17811774
ClassMethod SyncIrisWithRepoThroughDiff(ByRef files) As %Status
@@ -1809,10 +1802,7 @@ ClassMethod SyncIrisWithRepoThroughDiff(ByRef files) As %Status
18091802
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
18101803
}
18111804

1812-
set event = $classmethod(..PullEventClass(),"%New")
1813-
set event.LocalRoot = ..TempFolder()
1814-
merge event.ModifiedFiles = files
1815-
quit event.OnPull()
1805+
quit ##class(SourceControl.Git.PullEventHandler).ForModifications(.files)
18161806
}
18171807

18181808
ClassMethod GenerateCommitMessageFromFiles(filesWithActions) As %String

0 commit comments

Comments
 (0)