@@ -180,11 +180,7 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
180180 // cleanup items info
181181 kill @..#Storage@(" items" )
182182 kill @..#Storage@(" TSH" )
183- do ..RunGitCommand (" init" ,.errStream ,.outStream )
184- $$$NewLineIfNonEmptyStream(errStream )
185- do errStream .OutputToDevice ()
186- $$$NewLineIfNonEmptyStream(outStream )
187- do outStream .OutputToDevice ()
183+ do ..Init ()
188184 } else {
189185 set ec = ..MakeError (" Unable to create folder " _..TempFolder ())
190186 }
@@ -271,6 +267,16 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
271267 quit $$$OK
272268}
273269
270+ ClassMethod Init () As %Status
271+ {
272+ do ..RunGitCommand (" init" ,.errStream ,.outStream )
273+ $$$NewLineIfNonEmptyStream(errStream )
274+ do errStream .OutputToDevice ()
275+ $$$NewLineIfNonEmptyStream(outStream )
276+ do outStream .OutputToDevice ()
277+ quit $$$OK
278+ }
279+
274280ClassMethod Revert (InternalName As %String ) As %Status
275281{
276282 set filename = ..FullExternalName (.InternalName )
@@ -342,7 +348,7 @@ ClassMethod Fetch(ByRef diffFiles) As %Status
342348 quit $$$OK
343349}
344350
345- ClassMethod Pull (remote As %String = " origin" ) As %Status
351+ ClassMethod Pull (remote As %String = " origin" , preview As %Boolean = 0 ) As %Status
346352{
347353 #define Force 1
348354 do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" branch" ,,.errStream ,.outStream ," --show-current" )
@@ -376,7 +382,12 @@ ClassMethod Pull(remote As %String = "origin") As %Status
376382 }
377383 if ('$data (files )) {
378384 write !, ?4 , " None"
379- write !, " Already up to date. Git Pull will not be executed."
385+ if preview {
386+ quit $$$OK
387+ }
388+ write !, " Already up to date."
389+ quit $$$OK
390+ } elseif preview {
380391 quit $$$OK
381392 }
382393
@@ -423,6 +434,52 @@ ClassMethod Pull(remote As %String = "origin") As %Status
423434 quit event .OnPull ()
424435}
425436
437+ ClassMethod Clone (remote As %String ) As %Status
438+ {
439+ set settings = ##class (SourceControl.Git.Settings ).%New ()
440+ // TODO: eventually use /ENV flag with GIT_TERMINAL_PROMPT=0. (This isn't doc'd yet and is only in really new versions.)
441+ set sc = ..RunGitWithArgs (.errStream , .outStream , " clone" , remote , settings .namespaceTemp )
442+ $$$NewLineIfNonEmptyStream(errStream )
443+ while 'errStream .AtEnd {
444+ write errStream .ReadLine (),!
445+ }
446+ $$$NewLineIfNonEmptyStream(outStream )
447+ while 'outStream .AtEnd {
448+ write outStream .ReadLine (),!
449+ }
450+ quit $$$OK
451+ }
452+
453+ ClassMethod GenerateSSHKeyPair () As %Status
454+ {
455+ set settings = ##class (SourceControl.Git.Settings ).%New ()
456+ set filename = settings .privateKeyFile
457+ set email = settings .gitUserEmail
458+ set dir = ##class (%File ).GetDirectory (filename )
459+ if ##class (%File ).Exists (filename ) {
460+ Throw ##class (%Exception.General ).%New (" File " _filename _" already exists" )
461+ }
462+ do ##class (%File ).CreateDirectoryChain (dir )
463+ set outLog = ##class (%Library.File ).TempFilename ()
464+ set errLog = ##class (%Library.File ).TempFilename ()
465+ do $zf (-100 ," /SHELL /STDOUT=" _$$$QUOTE(outLog )_" /STDERR=" _$$$QUOTE(errLog ),
466+ " ssh-keygen" ,
467+ " -t" ," ed25519" ,
468+ " -C" ,email ,
469+ " -f" ,filename ,
470+ " -N" ," " )
471+
472+ set errStream = ##class (%Stream.FileCharacter ).%OpenId (errLog ,,.sc )
473+ set outStream = ##class (%Stream.FileCharacter ).%OpenId (outLog ,,.sc )
474+ set outStream .TranslateTable =" UTF8"
475+ for stream =errStream ,outStream {
476+ set stream .RemoveOnClose = 1
477+ }
478+ do outStream .OutputToDevice ()
479+ do errStream .OutputToDevice ()
480+ quit $$$OK
481+ }
482+
426483ClassMethod IsNamespaceInGit () As %Boolean [ CodeMode = expression ]
427484{
428485##class (%File ).Exists (..TempFolder ()_" .git" )
@@ -1789,15 +1846,22 @@ ClassMethod ConfigureWeb()
17891846 set installNamespace = $Namespace
17901847 new $Namespace
17911848 set $Namespace = " %SYS"
1792- write !," Adding favorite for all users... "
1849+ write !," Adding favorites for all users: "
17931850 set sql = " insert or update into %SYS_Portal.Users (Username, Page, Data) " _
17941851 " select ID,?,? from Security.Users"
17951852 set caption = " Git: " _installNamespace
17961853 set link = " /isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/" _installNamespace _" /"
1797- do ##class (%SQL.Statement ).%ExecDirect (,sql ,caption ,link ).%Display ()
1854+ write !," Adding Git favorite... "
1855+ set statement = ##class (%SQL.Statement ).%New ()
1856+ set statement .%SelectMode = 0
1857+ do ##class (%SQL.Statement ).%ExecDirect (statement ,sql ,caption ,link ).%Display ()
1858+ set caption = " Git Pull: " _installNamespace
1859+ set link = " /isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" _installNamespace
1860+ write !," Adding Git Pull favorite... "
1861+ do ##class (%SQL.Statement ).%ExecDirect (statement ,sql ,caption ,link ).%Display ()
17981862 write !," Setting GroupById to %ISCMgtPortal for /isc/studio/usertemplates... "
17991863 set sql = " update Security.Applications set GroupById='%ISCMgtPortal' where ID = '/isc/studio/usertemplates'"
1800- do ##class (%SQL.Statement ).%ExecDirect (,sql ).%Display ()
1864+ do ##class (%SQL.Statement ).%ExecDirect (statement ,sql ).%Display ()
18011865}
18021866
18031867ClassMethod CheckInitialization ()
@@ -1919,4 +1983,3 @@ ClassMethod BuildCEInstallationPackage(ByRef destination As %String) As %Status
19191983}
19201984
19211985}
1922-
0 commit comments