-
Notifications
You must be signed in to change notification settings - Fork 9
Fix production conflicts automatically (and more sync tweaks) #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ba13a10
wip: smarter behavior on rebase conflicts on production
isc-tleavitt 724d118
wip: more work toward smart XML three-way merge
isc-tleavitt 327369a
feat: automatically resolve common production conflict case
isc-tleavitt 5cbf1b6
Update CHANGELOG.md
isc-tleavitt 593c858
Merge branch 'main' into fix-production-conflicts
isc-tleavitt be5a51d
fix: various things for demo
isc-tleavitt 59859fe
now doesn't prompt for commit msg if no uncomitted files
isc-hwojnick ae774d0
changelog updated
isc-hwojnick 974e2b6
Merge remote-tracking branch 'origin/only-commit-msg-when-changes' in…
isc-tleavitt 9a35f64
feat: alert with warning if sync fails without commit
isc-tleavitt feff521
fix: diff handles renames on checkout
isc-tleavitt 47b1a45
Update ProductionConflictResolver.cls
isc-tleavitt 257ab0c
Merge in SQL security fixes to test
isc-tleavitt c82de15
fix: menu discard calls PullEventHandler
isc-tleavitt c6752f8
fix: sync rebase properly with diff
isc-tleavitt 3204031
Update CHANGELOG.md
isc-tleavitt b2dceed
Update CHANGELOG.md
isc-tleavitt 017a220
Merge branch 'main' into fix-production-conflicts
isc-tleavitt d4923f0
fix: only call %Extends if class defined
isc-tleavitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
cls/SourceControl/Git/Util/ProductionConflictResolver.cls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
Include (%occInclude, %occErrors, %occKeyword, %occReference, %occSAX) | ||
|
||
Class SourceControl.Git.Util.ProductionConflictResolver Extends %RegisteredObject | ||
{ | ||
|
||
Property logStream As %Stream.Object [ Private ]; | ||
|
||
Property productionFile As %String [ Private ]; | ||
|
||
Property productionClassname As %Dictionary.CacheClassname [ Private ]; | ||
|
||
Property errorStatus As %Status [ InitialExpression = 1, Private ]; | ||
|
||
/// API property: whether or not the conflict was resolved | ||
Property resolved As %Boolean [ InitialExpression = 0 ]; | ||
|
||
/// API property: error message if resolved is false | ||
Property errorMessage As %String [ Calculated ]; | ||
|
||
Method errorMessageGet() As %String | ||
{ | ||
If $$$ISERR(..errorStatus) { | ||
Do $System.Status.DecomposeStatus(..errorStatus,.components) | ||
If $Get(components(1,"code")) = $$$GeneralError { | ||
Quit $Get(components(1,"param",1)) | ||
} Else { | ||
Set ex = ##class(%Exception.StatusException).CreateFromStatus(..errorStatus) | ||
Do ex.Log() | ||
Quit "an internal error occurred and has been logged." | ||
} | ||
} Else { | ||
Quit "" | ||
} | ||
} | ||
|
||
ClassMethod FromLog(pOutStream As %Stream.Object) As SourceControl.Git.Util.ProductionConflictResolver | ||
{ | ||
Set inst = ..%New() | ||
Try { | ||
Set inst.logStream = pOutStream | ||
Do inst.ConsumeStream() | ||
Do inst.Resolve() | ||
} Catch e { | ||
Set inst.resolved = 0 | ||
Set inst.errorStatus = e.AsStatus() | ||
} | ||
Do inst.logStream.Rewind() // Finally | ||
Quit inst | ||
} | ||
|
||
Method ConsumeStream() [ Private ] | ||
{ | ||
Do ..logStream.Rewind() | ||
Do ..logStream.ReadLine() | ||
Set productionLine = ..logStream.ReadLine() | ||
Set ..productionFile = $Piece(productionLine,"Merge conflict in ",2) | ||
If ..productionFile = "" { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"Message did not reflect merge conflict on a single file.")) | ||
} | ||
If '..logStream.AtEnd { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"Multiple files had merge conflicts; cannot resolve intelligently.")) | ||
} | ||
Set internalName = ##class(SourceControl.Git.Utils).NameToInternalName(..productionFile) | ||
If ($Piece(internalName,".",*) '= "CLS") { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"File with conflict is not a class.")) | ||
} | ||
Set ..productionClassname = $Piece(internalName,".",1,*-1) | ||
If '($$$comClassDefined(..productionClassname) && $ClassMethod(..productionClassname,"%Extends","Ens.Production")) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"File with conflict is not an interoperability production.")) | ||
} | ||
} | ||
|
||
Method Resolve() [ Private ] | ||
{ | ||
Set filePath = ##class(SourceControl.Git.Utils).TempFolder()_..productionFile | ||
Set file = ##class(%Stream.FileCharacter).%OpenId(filePath,,.sc) | ||
$$$ThrowOnError(sc) | ||
|
||
Do ..ResolveStream(file) // Throws exception on failure | ||
|
||
$$$ThrowOnError(##class(SourceControl.Git.Utils).ImportItem(..productionClassname_".CLS",1)) | ||
$$$ThrowOnError($System.OBJ.Compile(..productionClassname,"ck")) | ||
|
||
// TODO: if we add multiple resolvers, move this to the end. | ||
set code = ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "add", ..productionFile) | ||
if (code '= 0) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"git add reported failure")) | ||
} | ||
set code = ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "commit", "--no-edit") | ||
if (code '= 0) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"git commit reported failure")) | ||
} | ||
|
||
set code = ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "rebase", "--continue") | ||
if (code '= 0) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"git rebase --continue reported failure")) | ||
} | ||
|
||
set ..resolved = 1 | ||
} | ||
|
||
/// Non-private to support unit testing | ||
ClassMethod ResolveStream(stream As %Stream.Object) | ||
{ | ||
// File may have: | ||
/* | ||
<<<<<<< HEAD | ||
<Item Name="Demo7" Category="" ClassName="EnsLib.CloudStorage.BusinessOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule=""> | ||
======= | ||
<Item Name="Demo5" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule=""> | ||
>>>>>>> 607d1f6 (modified src/HCC/Connect/Production.cls add Demo5) | ||
</Item> | ||
*/ | ||
|
||
// If: | ||
// * We have one such marker (<<<<<<< / ======= / >>>>>>>) | ||
// * The line after >>>>>> is "</Item>" | ||
// Then: | ||
// * We can replace ======= with "</Item>" | ||
|
||
Set copy = ##class(%Stream.TmpCharacter).%New() | ||
Set markerCount = 0 | ||
Set postCloseMarker = 0 | ||
While 'stream.AtEnd { | ||
Set line = stream.ReadLine() | ||
Set start = $Extract(line,1,7) | ||
If start = "<<<<<<<" { | ||
Set markerCount = markerCount + 1 | ||
Continue | ||
} ElseIf (start = ">>>>>>>") { | ||
Set postCloseMarker = 1 | ||
Continue | ||
} ElseIf (start = "=======") { | ||
Do copy.WriteLine(" </Item>") | ||
Continue | ||
} ElseIf postCloseMarker { | ||
If $ZStrip(line,"<>W") '= "</Item>" { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"The type of conflict encountered is not handled; user must resolve manually.")) | ||
} | ||
Set postCloseMarker = 0 | ||
} | ||
Do copy.WriteLine(line) | ||
} | ||
|
||
If markerCount > 1 { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"Multiple conflicts found, cannot resolve automatically.")) | ||
} ElseIf markerCount = 0 { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"No conflict markers found in file")) | ||
} | ||
|
||
$$$ThrowOnError(stream.CopyFromAndSave(copy)) | ||
|
||
Quit 1 | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.