@@ -79,6 +79,11 @@ ClassMethod GitUserEmail() As %String
79
79
Quit $Get (@..#Storage@(" settings" ," user" ,$username ," gitUserEmail" ))
80
80
}
81
81
82
+ ClassMethod PrivateKeyFile () As %String
83
+ {
84
+ Quit $Get (@..#Storage@(" settings" ," ssh" ," privateKeyFile" ))
85
+ }
86
+
82
87
ClassMethod NeedSettings () As %Boolean [ CodeMode = expression ]
83
88
{
84
89
(..DefaultTemp () = " " ) || (..GitBinPath () = " " ) || (..GitBinPath () = " " " " )
@@ -110,6 +115,7 @@ ClassMethod UpdateSettings(ByRef settings) As %Status
110
115
set @..#Storage@(" settings" ," groupByFolder" ) = $case (settings (" groupByFolder" ), " " :" " , :1 )
111
116
set @..#Storage@(" settings" ," user" ,$username ," gitUserName" ) = settings (" gitUserName" )
112
117
set @..#Storage@(" settings" ," user" ,$username ," gitUserEmail" ) = settings (" gitUserEmail" )
118
+ set @..#Storage@(" settings" ," ssh" ," privateKeyFile" ) = settings (" privateKeyFile" )
113
119
114
120
quit $$$OK
115
121
}
@@ -282,10 +288,11 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
282
288
quit $$$OK
283
289
}
284
290
285
- ClassMethod Push () As %Status
291
+ ClassMethod Push (remote As %String = " origin " ) As %Status
286
292
{
287
- do ..RunGitCommand (" push" , .errStream , .outStream )
288
- w " git push"
293
+ do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" branch" ,,.errStream ,.outstream ," --show-current" )
294
+ set branchName = outstream .ReadLine (outstream .Size )
295
+ do ..RunGitWithArgs (.errStream , .outStream , " push" , remote , branchName )
289
296
do errStream .OutputToDevice ()
290
297
do outStream .OutputToDevice ()
291
298
quit $$$OK
@@ -303,6 +310,8 @@ ClassMethod Fetch(ByRef diffFiles) As %Status
303
310
while (outStream .AtEnd = 0 ) {
304
311
set diffFiles = diffFiles _$lb (outStream .ReadLine ())
305
312
}
313
+ do outStream .Rewind ()
314
+ do outStream .OutputToDevice ()
306
315
quit $$$OK
307
316
}
308
317
@@ -311,33 +320,6 @@ ClassMethod Pull() As %Status
311
320
quit $$$OK
312
321
}
313
322
314
- ClassMethod ConfigureGitAuthentication (Username As %String , Password As %String )
315
- {
316
- //git config credential.helper store
317
- //write !,"git config --system credential.helper manager"
318
- //git config credential.helper '!f() { printf "%s\n" "username=$USER" "password=$PASS"; };f'
319
- do ..RunGitCommand (" config" , .errStream , .outStream , " --global" , " credential.helper" , " store" )
320
- do errStream .OutputToDevice ()
321
- do outStream .OutputToDevice ()
322
- /*
323
- write !,"git config --global credential.modalPrompt false"
324
- do ..RunGitCommand("config", .errStream, .outStream, "--global","credential.modalPrompt", "false")
325
- do errStream.OutputToDevice()
326
- do outStream.OutputToDevice()
327
- */
328
- /*
329
- set file = ##class(%Stream.FileCharacter).%New()
330
- do file.WriteLine(Username)
331
- do file.WriteLine(Password)
332
- $$$ThrowOnError(file.%Save())
333
- set file.RemoveOnClose = 1
334
- */
335
- write !," git fetch"
336
- do ..RunGitCommand (" fetch" , .errStream , .outStream )
337
- do errStream .OutputToDevice ()
338
- do outStream .OutputToDevice ()
339
- }
340
-
341
323
ClassMethod IsNamespaceInGit () As %Boolean [ CodeMode = expression ]
342
324
{
343
325
##class (%File ).Exists (..TempFolder ()_" .git" )
@@ -1093,6 +1075,17 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1093
1075
set newArgs ($i (newArgs )) = " -C"
1094
1076
set newArgs ($i (newArgs )) = ..TempFolder ()
1095
1077
1078
+ set privateKeyFile = ..PrivateKeyFile ()
1079
+ if (privateKeyFile '= " " ) {
1080
+ if $$$isWINDOWS {
1081
+ // Escape slashes
1082
+ set privateKeyFile = $Replace (privateKeyFile ," \" ," \\" )
1083
+ }
1084
+ set newArgs ($i (newArgs )) = " -c"
1085
+ // StrictHostKeyChecking=accept-new for good behavior on first connection
1086
+ set newArgs ($i (newArgs )) = " core.sshCommand=ssh -F /dev/null -o StrictHostKeyChecking=accept-new -i " _privateKeyFile
1087
+ }
1088
+
1096
1089
set username = ..GitUserName ()
1097
1090
set email = ..GitUserEmail ()
1098
1091
@@ -1110,10 +1103,12 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1110
1103
}
1111
1104
1112
1105
}
1113
-
1106
+
1114
1107
set outLog = ##class (%Library.File ).TempFilename ()
1115
1108
set errLog = ##class (%Library.File ).TempFilename ()
1109
+
1116
1110
set returnCode = $zf (-100 ," /STDOUT=" _$$$QUOTE(outLog )_" /STDERR=" _$$$QUOTE(errLog )_$Case (inFile , " " :" " , :" /STDIN=" _inFile )," git" ,newArgs ...)
1111
+
1117
1112
set errStream = ##class (%Stream.FileCharacter ).%OpenId (errLog ,,.sc )
1118
1113
set outStream = ##class (%Stream.FileCharacter ).%OpenId (outLog ,,.sc )
1119
1114
for stream =errStream ,outStream {
@@ -1306,3 +1301,4 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1) A
1306
1301
}
1307
1302
1308
1303
}
1304
+
0 commit comments