@@ -102,7 +102,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
102
102
do %request .Set (" EXPIRES" ,0 )
103
103
do ##class (%CSP.StreamServer ).OnPreHTTP () // Need to call this to set headers properly
104
104
set %stream = 1 // Leak this to webuidriver.csp
105
- } elseif $match (pathStart ," git-command|git|dirname|hostname|viewonly|discarded-states|restore-discarded|contexts|create-branch" ) {
105
+ } elseif $match (pathStart ," git-command|git|dirname|hostname|viewonly|discarded-states|restore-discarded|contexts|create-branch|git-command-unstage " ) {
106
106
if (%request .Method = " GET" ) {
107
107
set %data = ##class (%Stream.TmpCharacter ).%New ()
108
108
// Things not handled from Python backend:
@@ -220,36 +220,15 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
220
220
}
221
221
// Want to invoke merge conflict autoresolver in case of issues
222
222
set returnCode = ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" -c" ,inFile ,.errStream ,.outStream ,gitArgs ...)
223
-
224
- set %data = ##class (%Stream.TmpCharacter ).%New ()
225
- set changeTerminators = (%data .LineTerminator '= $char (13 ,10 ))
226
- set %data .LineTerminator = $char (13 ,10 ) // For the CSPGateway.
227
- do outStream .Rewind ()
228
- while 'outStream .AtEnd {
229
- do %data .WriteLine (outStream .ReadLine ())
230
- }
231
223
232
- set nLines = 0
233
- do errStream .Rewind ()
234
- while 'errStream .AtEnd {
235
- do %data .WriteLine (errStream .ReadLine ())
236
- set :changeTerminators nLines = nLines + 1
237
- }
224
+ do ..ConvertGitOutput (.outStream ,.errStream ,returnCode ,.%data )
238
225
239
- do %data .WriteLine (" Git-Stderr-Length: " _ (errStream .Size + nLines ))
240
- do %data .Write (" Git-Return-Code: " _ returnCode ) // No ending newline expected
241
- do %data .Rewind ()
242
226
if '$listfind (readOnlyCommands ,baseCommand ) {
243
227
do ##class (SourceControl.Git.Change ).RefreshUncommitted (,,,1 )
244
228
}
245
229
set handled = 1
246
230
} elseif (pathStart = " git-command" ) {
247
- set stringBody = " "
248
- while '%request .Content .AtEnd {
249
- set stringBody = stringBody _ %request .Content .Read ()
250
- }
251
- set stringBody = $zconvert (stringBody ," I" ," UTF8" )
252
- set requestBody = ##class (%Library.DynamicObject ).%FromJSON (stringBody )
231
+ do ..UnpackRequest (.%request , .requestBody )
253
232
set command = requestBody .command
254
233
255
234
set gitCmd = command .%Get (0 )
@@ -309,22 +288,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
309
288
do %data .Rewind ()
310
289
} else {
311
290
set returnCode = ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" -c" , inFile , .errStream , .outStream , argsArr ...)
312
- set %data = ##class (%Stream.TmpCharacter ).%New ()
313
- set changeTerminators = (%data .LineTerminator '= $char (13 ,10 ))
314
- set %data .LineTerminator = $char (13 ,10 ) // For the CSPGateway.
315
- while 'outStream .AtEnd {
316
- do %data .WriteLine (outStream .ReadLine ())
317
- }
318
-
319
- set nLines = 0
320
- while 'errStream .AtEnd {
321
- do %data .WriteLine (errStream .ReadLine ())
322
- set :changeTerminators nLines = nLines + 1
323
- }
324
-
325
- do %data .WriteLine (" Git-Stderr-Length: " _ (errStream .Size + nLines ))
326
- do %data .Write (" Git-Return-Code: " _ returnCode ) // No ending newline expected
327
- do %data .Rewind ()
291
+ do ..ConvertGitOutput (.outStream ,.errStream ,returnCode ,.%data )
328
292
}
329
293
set handled = 1
330
294
@@ -368,6 +332,41 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
368
332
}
369
333
set handled = 1
370
334
}
335
+ } elseif (pathStart = " git-command-unstage" ) {
336
+ do ..UnpackRequest (.%request , .requestBody )
337
+
338
+ set flags = requestBody .flags
339
+ if (flags '= " " ) {
340
+ set flaglist = $listfromstring (flags ," ," )
341
+ for i =1 :1 :$listlength (flaglist ) {
342
+ set flag = $listget (flaglist ,i )
343
+ set args ($increment (args )) = flag
344
+ }
345
+ }
346
+ set message = requestBody .message
347
+ if (message '= " " ) {
348
+ set args ($increment (args )) = " -m"
349
+ set args ($increment (args )) = message
350
+ }
351
+ set details = requestBody .details
352
+ if (details '= " " ) {
353
+ set args ($increment (args )) = " -m"
354
+ set args ($increment (args )) = details
355
+ }
356
+ set command = requestBody .command
357
+
358
+ // Extract Files
359
+ set fileList = []
360
+ set files = requestBody .files
361
+ set iter = files .%GetIterator ()
362
+ while iter .%GetNext (,.value ) {
363
+ do fileList .%Push (value )
364
+ }
365
+
366
+ set returnCode = ##class (SourceControl.Git.Utils ).RunGitCommandReStage (.outStream ,.errStream ,command ,.fileList ,args ...)
367
+
368
+ do ..ConvertGitOutput (.outStream ,.errStream ,returnCode ,.%data )
369
+ set handled = 1
371
370
}
372
371
}
373
372
}
@@ -465,4 +464,38 @@ ClassMethod GetRemote() As %Library.DynamicObject
465
464
quit {" remote" : (remote )}
466
465
}
467
466
467
+ ClassMethod UnpackRequest (ByRef %request As %CSP .Request , Output obj As %Library .DynamicObject ) As %Status
468
+ {
469
+ set stringBody = " "
470
+ while '%request .Content .AtEnd {
471
+ set stringBody = stringBody _ %request .Content .Read ()
472
+ }
473
+ set stringBody = $zconvert (stringBody ," I" ," UTF8" )
474
+ set obj = ##class (%Library.DynamicObject ).%FromJSON (stringBody )
475
+ return $$$OK
476
+ }
477
+
478
+ ClassMethod ConvertGitOutput (ByRef outStream , ByRef errStream , returnCode As %String , Output %data ) As %Status
479
+ {
480
+ set %data = ##class (%Stream.TmpCharacter ).%New ()
481
+ set changeTerminators = (%data .LineTerminator '= $char (13 ,10 ))
482
+ set %data .LineTerminator = $char (13 ,10 ) // For the CSPGateway.
483
+ do outStream .Rewind ()
484
+ while 'outStream .AtEnd {
485
+ do %data .WriteLine (outStream .ReadLine ())
486
+ }
487
+
488
+ set nLines = 0
489
+ do errStream .Rewind ()
490
+ while 'errStream .AtEnd {
491
+ do %data .WriteLine (errStream .ReadLine ())
492
+ set :changeTerminators nLines = nLines + 1
493
+ }
494
+
495
+ do %data .WriteLine (" Git-Stderr-Length: " _ (errStream .Size + nLines ))
496
+ do %data .Write (" Git-Return-Code: " _ returnCode ) // No ending newline expected
497
+ do %data .Rewind ()
498
+ return $$$OK
499
+ }
500
+
468
501
}
0 commit comments