@@ -102,7 +102,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
102102 do %request .Set (" EXPIRES" ,0 )
103103 do ##class (%CSP.StreamServer ).OnPreHTTP () // Need to call this to set headers properly
104104 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 " ) {
106106 if (%request .Method = " GET" ) {
107107 set %data = ##class (%Stream.TmpCharacter ).%New ()
108108 // Things not handled from Python backend:
@@ -220,36 +220,15 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
220220 }
221221 // Want to invoke merge conflict autoresolver in case of issues
222222 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- }
231223
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 )
238225
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 ()
242226 if '$listfind (readOnlyCommands ,baseCommand ) {
243227 do ##class (SourceControl.Git.Change ).RefreshUncommitted (,,,1 )
244228 }
245229 set handled = 1
246230 } 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 )
253232 set command = requestBody .command
254233
255234 set gitCmd = command .%Get (0 )
@@ -309,22 +288,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
309288 do %data .Rewind ()
310289 } else {
311290 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 )
328292 }
329293 set handled = 1
330294
@@ -368,6 +332,41 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
368332 }
369333 set handled = 1
370334 }
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
371370 }
372371 }
373372 }
@@ -465,4 +464,38 @@ ClassMethod GetRemote() As %Library.DynamicObject
465464 quit {" remote" : (remote )}
466465}
467466
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+
468501}
0 commit comments