Skip to content

Fixes #366 Add merge to sync flow #376

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 6 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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


## [2.3.1] - 2024-04-30
Expand Down
1 change: 1 addition & 0 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
set Enabled = $CASE(name,
"Status": 1,
"GitWebUI" : 1,
"NewBranch": 1,
"Sync": 1,
"": 1,
:-1
Expand Down
4 changes: 4 additions & 0 deletions cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Property userBasicMode As %String [ InitialExpression = {##class(SourceControl.G
/// The system's default mode. If true, the system defaults to basic mode
Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).SystemBasicMode()} ];

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

Property Mappings [ MultiDimensional ];

Method %OnNew() As %Status
Expand Down Expand Up @@ -93,6 +96,7 @@ Method %Save() As %Status
set @storage@("settings","percentClassReplace") = ..percentClassReplace
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
set @storage@("settings", "defaultMergeBranch") = ..defaultMergeBranch
set @storage@("settings", "basicMode") = ..systemBasicMode
if ..basicMode = "system" {
kill @storage@("settings", "user", $username, "basicMode")
Expand Down
29 changes: 29 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ ClassMethod SystemBasicMode() As %Boolean
quit $get(@..#Storage@("settings", "basicMode"), 0)
}

ClassMethod DefaultMergeBranch() As %String
{
quit $get(@..#Storage@("settings", "defaultMergeBranch"), "")
}

ClassMethod MappedItemsReadOnly() As %Boolean
{
quit $get(@..#Storage@("settings", "mappedItemsReadOnly"), 1)
Expand Down Expand Up @@ -335,6 +340,16 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit

ClassMethod NewBranch(newBranchName As %String) As %Status
{
set settings = ##class(SourceControl.Git.Settings).%New()
if (settings.basicMode) && (settings.defaultMergeBranch '= ""){
do ..RunGitWithArgs(.errStream, .outStream, "checkout", settings.defaultMergeBranch)
do ..PrintStreams(errStream, outStream)
kill errStream, outStream
do ..RunGitWithArgs(.errStream, .outStream, "pull")
do ..PrintStreams(errStream, outStream)
kill errStream, outStream
}

do ..RunGitWithArgs(.errStream, .outStream, "checkout", "-b", newBranchName)
do ..PrintStreams(errStream, outStream)
quit $$$OK
Expand Down Expand Up @@ -379,6 +394,17 @@ ClassMethod StageAddedFiles()
}
}

/// Merges the files from the configured branch as part of the Sync operation
ClassMethod MergeDefaultRemoteBranch()
{
set settings = ##class(SourceControl.Git.Settings).%New()
set defaultMergeBranch = settings.defaultMergeBranch
if defaultMergeBranch '= "" {
do ..RunGitWithArgs(.errStream, .outStream, "rebase", defaultMergeBranch)
do ..PrintStreams(errStream, outStream)
}
}

/// Converts the DynamicArray into a list and calls the SourceControl.Git.Change RemoveUncommitted method on the newly created list
ClassMethod ClearUncommitted(filesWithActions) As %Status
{
Expand All @@ -405,6 +431,9 @@ ClassMethod Sync(Msg As %String) As %Status
do ..Pull()
do ..SyncCommit(Msg)
do ..Push()
do ..MergeDefaultRemoteBranch()
do ..Push()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to Push after the merge as well, so that the merge is reflected in the remote.

}

quit $$$OK
Expand Down
9 changes: 8 additions & 1 deletion csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ body {
set $Property(settings,param) = $Get(%request.Data(param,1))
}
if ('settings.settingsUIReadOnly) {
for param="gitBinPath","namespaceTemp","privateKeyFile","pullEventClass","percentClassReplace" {
for param="gitBinPath","namespaceTemp","privateKeyFile","pullEventClass","percentClassReplace", "defaultMergeBranch" {
set $Property(settings,param) = $Get(%request.Data(param,1))
}

Expand Down Expand Up @@ -308,6 +308,13 @@ body {


</div>

<div class="form-group row mb-3">
<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>
<div class="col-sm-7">
<input type="text" class="form-control" id="defaultMergeBranch" name="defaultMergeBranch" value='#(..EscapeHTML(settings.defaultMergeBranch))#' placeholder="sample-remote-branch">
</div>
</div>

<div class="form-group row mb-3">
<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>
Expand Down
Loading