@@ -303,6 +303,9 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
303
303
do ..Sync (Msg )
304
304
set Reload = 1
305
305
}
306
+ } elseif (menuItemName = " GitWebUI" ) {
307
+ // Always force reload as many things could have possibly changed.
308
+ set Reload = 1
306
309
}
307
310
quit $$$OK
308
311
}
@@ -395,14 +398,49 @@ ClassMethod StageAddedFiles()
395
398
}
396
399
397
400
/// Merges the files from the configured branch as part of the Sync operation
398
- ClassMethod MergeDefaultRemoteBranch ()
401
+ /// Returns true if this resulted in durable changes to the local git repo
402
+ ClassMethod MergeDefaultRemoteBranch (Output alert As %String = " " ) As %Boolean
399
403
{
404
+ set rebased = 0
400
405
set settings = ##class (SourceControl.Git.Settings ).%New ()
401
406
set defaultMergeBranch = settings .defaultMergeBranch
402
407
if defaultMergeBranch '= " " {
403
- do ..RunGitWithArgs (.errStream , .outStream , " rebase " , defaultMergeBranch )
408
+ do ..RunGitWithArgs (.errStream , .outStream , " fetch " , " origin " , defaultMergeBranch _ " : " _ defaultMergeBranch )
404
409
do ..PrintStreams (errStream , outStream )
410
+
411
+ // Start a transaction so code changes can be rolled back
412
+ set initTLevel = $TLevel
413
+ try {
414
+ TSTART
415
+ set code = ..RunGitWithArgs (.errStream , .outStream , " rebase" , defaultMergeBranch )
416
+ if (code '= 0 ) {
417
+ $$$ThrowStatus($$$ERROR($$$GeneralError," git rebase reported failure" ))
418
+ }
419
+ set rebased = 1
420
+ TCOMMIT
421
+ } catch e {
422
+ // "rebase" may throw an exception due to errors syncing to IRIS. In that case, roll back and keep going to abort the rebase.
423
+ write !," Attempting to resolve differences in production definition..."
424
+ set resolver = ##class (SourceControl.Git.Util.ProductionConflictResolver ).FromLog (outStream )
425
+ write !! zw resolver write !!
426
+ if resolver .resolved {
427
+ set rebased = 1
428
+ write " success!"
429
+ } else {
430
+ write " unable to resolve - " _resolver .errorMessage
431
+ while $TLevel > initTLevel {
432
+ TROLLBACK 1
433
+ }
434
+ }
435
+ }
436
+ if 'rebased {
437
+ do ..RunGitCommand (" rebase" ,.errStream , .outStream ," --abort" )
438
+ do ..PrintStreams (errStream , outStream )
439
+ set alert = " WARNING: Remote branch '" _defaultMergeBranch _" ' could not be merged due to conflicts. Changes have been pushed to '" _..GetCurrentBranch ()_" ' and must be resolved in your git remote."
440
+ write !,alert ,!
441
+ }
405
442
}
443
+ quit rebased
406
444
}
407
445
408
446
/// Converts the DynamicArray into a list and calls the SourceControl.Git.Change RemoveUncommitted method on the newly created list
@@ -419,7 +457,7 @@ ClassMethod ClearUncommitted(filesWithActions) As %Status
419
457
quit $$$OK
420
458
}
421
459
422
- ClassMethod Sync (Msg As %String ) As %Status
460
+ ClassMethod Sync (Msg As %String , Output alert As %String ) As %Status
423
461
{
424
462
write !, " Syncing local repository..." , !
425
463
do ..StageAddedFiles ()
@@ -430,20 +468,24 @@ ClassMethod Sync(Msg As %String) As %Status
430
468
do ..Fetch ()
431
469
do ..Pull ()
432
470
do ..SyncCommit (Msg )
433
- do ..Push ()
434
- do ..MergeDefaultRemoteBranch ()
435
- do ..Push ()
436
-
471
+ do ..Push (, 1 )
472
+ if ..MergeDefaultRemoteBranch (. alert ) {
473
+ do ..Push (, 1 )
474
+ }
437
475
}
438
-
439
476
quit $$$OK
440
477
}
441
478
442
- ClassMethod Push (remote As %String = " origin" ) As %Status
479
+ ClassMethod Push (remote As %String = " origin" , force As %Boolean = 0 ) As %Status
443
480
{
444
481
do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" branch" ,,.errStream ,.outstream ," --show-current" )
445
482
set branchName = outstream .ReadLine (outstream .Size )
446
- do ..RunGitWithArgs (.errStream , .outStream , " push" , remote , branchName )
483
+ if (force ) {
484
+ set args ($i (args )) = " --force"
485
+ }
486
+ set args ($i (args )) = remote
487
+ set args ($i (args )) = branchName
488
+ do ..RunGitWithArgs (.errStream , .outStream , " push" , args ...)
447
489
do ..PrintStreams (errStream , outStream )
448
490
quit $$$OK
449
491
}
@@ -475,7 +517,7 @@ ClassMethod Pull(remote As %String = "origin") As %Status
475
517
set branchName = outStream .ReadLine (outStream .Size )
476
518
write !, " Pulling from branch: " , branchName
477
519
kill errStream , outStream
478
- set returnCode = ..RunGitWithArgs (.errStream , .outStream , " pull" , remote _ " / " _ branchName )
520
+ set returnCode = ..RunGitWithArgs (.errStream , .outStream , " pull" , remote , branchName )
479
521
480
522
w !, " Pull ran with return code: " _ returnCode
481
523
quit $$$OK
@@ -1226,6 +1268,7 @@ ClassMethod ImportCSPFile(InternalName As %String) As %Status
1226
1268
ClassMethod ListItemsInFiles (ByRef itemList , ByRef err ) As %Status
1227
1269
{
1228
1270
#define DoNotLoad 1
1271
+ set res = $$$OK
1229
1272
1230
1273
set mappingFileType = $order ($$$SourceMapping(" " ))
1231
1274
while (mappingFileType '= " " ) {
@@ -1536,7 +1579,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1536
1579
{
1537
1580
set pullArg = " "
1538
1581
if command = " pull" {
1539
- set pullArg = args (1 )
1582
+ set pullArg = $Get ( args (1 ) )
1540
1583
}
1541
1584
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
1542
1585
if (command '= " --version" ) {
@@ -1570,12 +1613,13 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1570
1613
set diffBase = " "
1571
1614
set diffCompare = " "
1572
1615
set pullOriginIndex = " "
1573
- if (command = " checkout" ) || (command = " merge" ) || (command = " rebase" ) || (command = " pull" ){
1616
+ if (command = " checkout" ) || (command = " merge" ) || (command = " rebase" ) || (command = " pull" ) {
1574
1617
set syncIris = 1
1575
- set diffCompare = args (args )
1618
+ if $data (args ) && $data (args (args ),diffCompare ) {
1619
+ // no-op
1620
+ }
1576
1621
}
1577
1622
1578
-
1579
1623
for i =1 :1 :$get (args ) {
1580
1624
if ($data (args (i ))) {
1581
1625
set newArgs ($increment (newArgs )) = args (i )
@@ -1607,7 +1651,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1607
1651
}
1608
1652
do ..RunGitCommand (" fetch" , .errorStream , .outputStream )
1609
1653
kill errorStream , outputStream
1610
- do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errorStream ,.outputStream , diffBase _" .." _diffCompare , " --name-status" )
1654
+ do ##class (SourceControl.Git.Utils ).RunGitCommandWithInput (" diff" ,,.errorStream ,.outputStream , diffBase _$Case ( diffCompare , " " : " " ,: " .." ) _diffCompare , " --name-status" )
1611
1655
while (outputStream .AtEnd = 0 ) {
1612
1656
set file = outputStream .ReadLine ()
1613
1657
set modification = ##class (SourceControl.Git.Modification ).%New ()
@@ -1656,8 +1700,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
1656
1700
for stream =errStream ,outStream {
1657
1701
set stream .RemoveOnClose = 1
1658
1702
}
1659
- do ..PrintStreams (errStream , outStream )
1660
1703
if syncIris {
1704
+ do ..PrintStreams (errStream , outStream )
1661
1705
$$$ThrowOnError(..SyncIrisWithRepo (.files ))
1662
1706
}
1663
1707
quit returnCode
0 commit comments