Skip to content

Commit 4834974

Browse files
authored
Merge pull request #376 from intersystems/add-merge-to-sync-flow
Fixes #366 Add merge to sync flow
2 parents a3b976f + fee5a7f commit 4834974

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Now skips files belonging to other git enabled packages in `##class(SourceControl.Git.Change).RefreshUncommitted()` (#347)
1818
- Added a new "Branch" parameter to `##class(SourceControl.Git.PullEventHandler)` (#351)
1919
- Command-line utility to do a baseline export of items in a namespace
20+
- 'New Branch' menu option in basic now will create new branches from the configured default merge branch
21+
- Merging back with the default merge branch is now a part of the basic mode's Sync flow
2022

2123
### Fixed
2224
- Menu items names are properly translated from internal name in VSCode, Management Portal (#372)

cls/SourceControl/Git/Extension.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
124124
set Enabled = $CASE(name,
125125
"Status": 1,
126126
"GitWebUI" : 1,
127+
"NewBranch": 1,
127128
"Sync": 1,
128129
"": 1,
129130
:-1

cls/SourceControl/Git/Settings.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Property userBasicMode As %String [ InitialExpression = {##class(SourceControl.G
4141
/// The system's default mode. If true, the system defaults to basic mode
4242
Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).SystemBasicMode()} ];
4343

44+
/// In Basic mode, Sync will merge changes from this remote branch
45+
Property defaultMergeBranch As %String [ InitialExpression = {##class(SourceControl.Git.Utils).DefaultMergeBranch()} ];
46+
4447
Property Mappings [ MultiDimensional ];
4548

4649
Method %OnNew() As %Status
@@ -93,6 +96,7 @@ Method %Save() As %Status
9396
set @storage@("settings","percentClassReplace") = ..percentClassReplace
9497
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
9598
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
99+
set @storage@("settings", "defaultMergeBranch") = ..defaultMergeBranch
96100
set @storage@("settings", "basicMode") = ..systemBasicMode
97101
if ..basicMode = "system" {
98102
kill @storage@("settings", "user", $username, "basicMode")

cls/SourceControl/Git/Utils.cls

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ ClassMethod SystemBasicMode() As %Boolean
128128
quit $get(@..#Storage@("settings", "basicMode"), 0)
129129
}
130130

131+
ClassMethod DefaultMergeBranch() As %String
132+
{
133+
quit $get(@..#Storage@("settings", "defaultMergeBranch"), "")
134+
}
135+
131136
ClassMethod MappedItemsReadOnly() As %Boolean
132137
{
133138
quit $get(@..#Storage@("settings", "mappedItemsReadOnly"), 1)
@@ -335,6 +340,16 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
335340

336341
ClassMethod NewBranch(newBranchName As %String) As %Status
337342
{
343+
set settings = ##class(SourceControl.Git.Settings).%New()
344+
if (settings.basicMode) && (settings.defaultMergeBranch '= ""){
345+
do ..RunGitWithArgs(.errStream, .outStream, "checkout", settings.defaultMergeBranch)
346+
do ..PrintStreams(errStream, outStream)
347+
kill errStream, outStream
348+
do ..RunGitWithArgs(.errStream, .outStream, "pull")
349+
do ..PrintStreams(errStream, outStream)
350+
kill errStream, outStream
351+
}
352+
338353
do ..RunGitWithArgs(.errStream, .outStream, "checkout", "-b", newBranchName)
339354
do ..PrintStreams(errStream, outStream)
340355
quit $$$OK
@@ -379,6 +394,17 @@ ClassMethod StageAddedFiles()
379394
}
380395
}
381396

397+
/// Merges the files from the configured branch as part of the Sync operation
398+
ClassMethod MergeDefaultRemoteBranch()
399+
{
400+
set settings = ##class(SourceControl.Git.Settings).%New()
401+
set defaultMergeBranch = settings.defaultMergeBranch
402+
if defaultMergeBranch '= "" {
403+
do ..RunGitWithArgs(.errStream, .outStream, "rebase", defaultMergeBranch)
404+
do ..PrintStreams(errStream, outStream)
405+
}
406+
}
407+
382408
/// Converts the DynamicArray into a list and calls the SourceControl.Git.Change RemoveUncommitted method on the newly created list
383409
ClassMethod ClearUncommitted(filesWithActions) As %Status
384410
{
@@ -405,6 +431,9 @@ ClassMethod Sync(Msg As %String) As %Status
405431
do ..Pull()
406432
do ..SyncCommit(Msg)
407433
do ..Push()
434+
do ..MergeDefaultRemoteBranch()
435+
do ..Push()
436+
408437
}
409438

410439
quit $$$OK

csp/gitprojectsettings.csp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ body {
8080
set $Property(settings,param) = $Get(%request.Data(param,1))
8181
}
8282
if ('settings.settingsUIReadOnly) {
83-
for param="gitBinPath","namespaceTemp","privateKeyFile","pullEventClass","percentClassReplace" {
83+
for param="gitBinPath","namespaceTemp","privateKeyFile","pullEventClass","percentClassReplace", "defaultMergeBranch" {
8484
set $Property(settings,param) = $Get(%request.Data(param,1))
8585
}
8686

@@ -308,6 +308,13 @@ body {
308308

309309

310310
</div>
311+
312+
<div class="form-group row mb-3">
313+
<label for="defaultMergeBranch" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="In basic mode, the Sync operation will merge changes from this remote branch (leave blank for no branch)">Default merge branch</label>
314+
<div class="col-sm-7">
315+
<input type="text" class="form-control" id="defaultMergeBranch" name="defaultMergeBranch" value='#(..EscapeHTML(settings.defaultMergeBranch))#' placeholder="sample-remote-branch">
316+
</div>
317+
</div>
311318

312319
<div class="form-group row mb-3">
313320
<label for="mappedItemsReadOnly" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Whether items mapped from a database other than this namespace's default routine database should be read-only. If enabled, mapped items won't be saved to source control or exported. NOTE: These are different from the mappings configured in this settings page"> Treat Mapped Items as Read-only</label>

0 commit comments

Comments
 (0)