Skip to content

no Commits on default merge branch in basic mode #536

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
Oct 21, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed display of other users' username in workspace view on Unix (#530)
- Fixed slowness loading some CSP pages with multiple instances sharing a webserver (#540)
- Prevent direct commits to default merge branch in basic mode (#484)

## [2.6.0] - 2024-10-07

Expand Down
9 changes: 9 additions & 0 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
quit $$$OK
}

if (menuItemName = "Commit") {
set defaultBasic = ##class(SourceControl.Git.Utils).InDefaultBranchBasicMode()
if (defaultBasic) {
Set Target = "WARNING: Please create a new branch before committing."
set Action = 6
quit $$$OK
}
}

if (menuItemName = "Commit") || (menuItemName = "Sync") {
if ..CheckCommitterIdentity(settings, .Action, .Target) {
quit $$$OK
Expand Down
17 changes: 17 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ ClassMethod Sync(Msg As %String, Output alert As %String) As %Status
if '..HasRemoteRepo() {
write "No remote repository configured: skipping fetch, pull and push"
do ..SyncCommit(Msg)
} elseif ..InDefaultBranchBasicMode() {
// Do not commit to default merge branch in basic mode
write "In Basic mode on default merge branch: skipping commit and push"
do ..Fetch()
do ..Pull()
} else {
do ..Fetch()
do ..Pull()
Expand Down Expand Up @@ -2832,4 +2837,16 @@ ClassMethod SetConfiguredRemote(url) As %String
quit output
}

// Returns true if the current branch is the default merge branch and we are in basic mode

ClassMethod InDefaultBranchBasicMode() As %Boolean
{
set basicMode = ..BasicMode()
set default = ..DefaultMergeBranch()
do ##class(SourceControl.Git.Utils).RunGitCommand("branch",.err,.out,"--show-current")
set current = out.ReadLine()
if (basicMode && (default = current)) { quit 1 }
quit 0
}

}
4 changes: 4 additions & 0 deletions cls/SourceControl/Git/WebUIDriver.cls
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
set responseJSON = {
"environment": (##class(SourceControl.Git.Utils).EnvironmentName())
}
} elseif $extract(pagePath, 6, *) = "basic-and-default" {
set responseJSON = {
"basic-and-default": (##class(SourceControl.Git.Utils).InDefaultBranchBasicMode())
}
} else {
set %response.Status = ##class(%CSP.REST).#HTTP404NOTFOUND
set responseJSON = {"error":("invalid URI: " _ pagePath)}
Expand Down
36 changes: 36 additions & 0 deletions csp/sync.csp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@
border-radius: 4px;
}

/* The alert message box */
.alert {
padding: 20px;
background-color: #f44336; /* Red */
color: white;
margin-bottom: 15px;
}

/* The close button */
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}

/* When moving the mouse over the close button */
.closebtn:hover {
color: black;
}


</style>
</head>
<body>
Expand All @@ -83,6 +109,16 @@
<h1 class="text-center">Sync Repository</h1>
<div class="row">
<div class="offset-sm-2 col-sm-8">
<server>
if ##class(SourceControl.Git.Utils).InDefaultBranchBasicMode() {
&html<
<div class = "alert">
<span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span>
<strong>Warning!</strong> Please change branches to make sure your changes are committed.
</div>
>
}
</server>
<div style="display: #(fileSectionDisplay)#">
<h3 class="section-header">Files to be committed with sync:</h3>
<ul class="list-group">
Expand Down
70 changes: 63 additions & 7 deletions git-webui/release/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2598,13 +2598,20 @@ webui.NewChangedFilesView = function(workspaceView) {
});
$("#commitBtn").off("click");
$("#commitBtn").on("click", function() {
if (selectedItemsFromOtherUser.length > 0) {
self.confirmActionOnOtherUsersChanges("commit");
} else {
var commitMessage = $('#commitMsg').val();
self.commit(commitMessage, $("#commitMsgDetail").val());
}

// Make sure we are not commiting to default merge branch in basic mode
$.get("api/basic-and-default", function (data) {
var basicAndDefault = JSON.parse(data)["basic-and-default"]
if (basicAndDefault == "1") {
self.noCommitsOnDefault();
} else {
if (selectedItemsFromOtherUser.length > 0) {
self.confirmActionOnOtherUsersChanges("commit");
} else {
var commitMessage = $('#commitMsg').val();
self.commit(commitMessage, $("#commitMsgDetail").val());
}
}
})
});

$("#amendBtn").off("click");
Expand Down Expand Up @@ -2749,6 +2756,55 @@ webui.NewChangedFilesView = function(workspaceView) {
});
}

// Popup for when trying to commit to default merge branch in basic mode
self.noCommitsOnDefault = function () {
function removePopup(popup) {
$(popup).children(".modal-fade").modal("hide");
$(".modal-backdrop").remove();
$("#noCommitsDefault").remove();
}

var popup = $(
'<div class="modal fade" tabindex="-1" id="noCommitsDefault" role="dialog" data-backdrop="static">' +
'<div class="modal-dialog modal-md" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<h5 class="modal-title">Cannot commit to Default Branch</h5>' +
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
'</div>' +
'<div class="modal-body">' +
'<div class="row">' +
'<div class="col-sm-1">' +
webui.warningIcon +
'</div>' +
'<div class="col-sm-11">' +
'<p>You cannot commit directly to the default merge branch while using basic mode. Please switch to another branch.</p>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="modal-footer"></div>' +
'</div>' +
'</div>' +
'</div>'
)[0];

$("body").append(popup);

var popupFooter = $(".modal-footer", popup)[0];
webui.detachChildren(popupFooter);

$(
'<button class="btn btn-sm btn-secondary action-btn" id="noCommitDefaultButton">Ok</button>'
).appendTo(popupFooter);

$(popup).modal('show');

$("#noCommitsDefault").find(".close, #noCommitDefaultButton").click(function() {
removePopup(popup);
})

};

self.confirmActionOnOtherUsersChanges = function(action) {
function removeWarningModal(popup) {
$(popup).children(".modal-fade").modal("hide");
Expand Down
70 changes: 63 additions & 7 deletions git-webui/src/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2598,13 +2598,20 @@ webui.NewChangedFilesView = function(workspaceView) {
});
$("#commitBtn").off("click");
$("#commitBtn").on("click", function() {
if (selectedItemsFromOtherUser.length > 0) {
self.confirmActionOnOtherUsersChanges("commit");
} else {
var commitMessage = $('#commitMsg').val();
self.commit(commitMessage, $("#commitMsgDetail").val());
}

// Make sure we are not commiting to default merge branch in basic mode
$.get("api/basic-and-default", function (data) {
var basicAndDefault = JSON.parse(data)["basic-and-default"]
if (basicAndDefault == "1") {
self.noCommitsOnDefault();
} else {
if (selectedItemsFromOtherUser.length > 0) {
self.confirmActionOnOtherUsersChanges("commit");
} else {
var commitMessage = $('#commitMsg').val();
self.commit(commitMessage, $("#commitMsgDetail").val());
}
}
})
});

$("#amendBtn").off("click");
Expand Down Expand Up @@ -2749,6 +2756,55 @@ webui.NewChangedFilesView = function(workspaceView) {
});
}

// Popup for when trying to commit to default merge branch in basic mode
self.noCommitsOnDefault = function () {
function removePopup(popup) {
$(popup).children(".modal-fade").modal("hide");
$(".modal-backdrop").remove();
$("#noCommitsDefault").remove();
}

var popup = $(
'<div class="modal fade" tabindex="-1" id="noCommitsDefault" role="dialog" data-backdrop="static">' +
'<div class="modal-dialog modal-md" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<h5 class="modal-title">Cannot commit to Default Branch</h5>' +
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
'</div>' +
'<div class="modal-body">' +
'<div class="row">' +
'<div class="col-sm-1">' +
webui.warningIcon +
'</div>' +
'<div class="col-sm-11">' +
'<p>You cannot commit directly to the default merge branch while using basic mode. Please switch to another branch.</p>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="modal-footer"></div>' +
'</div>' +
'</div>' +
'</div>'
)[0];

$("body").append(popup);

var popupFooter = $(".modal-footer", popup)[0];
webui.detachChildren(popupFooter);

$(
'<button class="btn btn-sm btn-secondary action-btn" id="noCommitDefaultButton">Ok</button>'
).appendTo(popupFooter);

$(popup).modal('show');

$("#noCommitsDefault").find(".close, #noCommitDefaultButton").click(function() {
removePopup(popup);
})

};

self.confirmActionOnOtherUsersChanges = function(action) {
function removeWarningModal(popup) {
$(popup).children(".modal-fade").modal("hide");
Expand Down
Loading