Skip to content

Commit 1c9c9dc

Browse files
committed
No commits on default merge branch in basic mode
Disallow commits on default merge branch in basic mode; Remove commits and pushing form sync in basic mode on default merge branch
1 parent 92c80cb commit 1c9c9dc

File tree

5 files changed

+143
-14
lines changed

5 files changed

+143
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414
- Fixed display of other users' username in workspace view on Unix (#530)
15+
- Prevent direct commits to default merge branch in basic mode (#484)
1516

1617
## [2.6.0] - 2024-10-07
1718

cls/SourceControl/Git/Utils.cls

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ ClassMethod Sync(Msg As %String, Output alert As %String) As %Status
518518
if '..HasRemoteRepo() {
519519
write "No remote repository configured: skipping fetch, pull and push"
520520
do ..SyncCommit(Msg)
521+
} elseif ..InDefaultBranchBasicMode() {
522+
write "In Basic mode on default merge branch: skipping commit and push"
523+
do ..Fetch()
524+
do ..Pull()
521525
} else {
522526
do ..Fetch()
523527
do ..Pull()
@@ -2798,4 +2802,16 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
27982802
return sc
27992803
}
28002804

2805+
// Returns true if the current branch is the default merge branch and we are in basic mode
2806+
2807+
ClassMethod InDefaultBranchBasicMode() As %Boolean
2808+
{
2809+
set basicMode = ..BasicMode()
2810+
set default = ..DefaultMergeBranch()
2811+
do ##class(SourceControl.Git.Utils).RunGitCommand("branch",.err,.out,"--show-current")
2812+
set current = out.ReadLine()
2813+
if (basicMode && (default = current)) { quit 1 }
2814+
quit 0
2815+
}
2816+
28012817
}

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
2626
set responseJSON = {
2727
"url": (..GetHomeURL())
2828
}
29+
} elseif $extract(pagePath, 6, *) = "basic-and-default" {
30+
set responseJSON = {
31+
"basic-and-default": (##class(SourceControl.Git.Utils).InDefaultBranchBasicMode())
32+
}
2933
} else {
3034
set %response.Status = ##class(%CSP.REST).#HTTP404NOTFOUND
3135
set responseJSON = {"error":("invalid URI: " _ pagePath)}

git-webui/release/share/git-webui/webui/js/git-webui.js

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,13 +2588,19 @@ webui.NewChangedFilesView = function(workspaceView) {
25882588
});
25892589
$("#commitBtn").off("click");
25902590
$("#commitBtn").on("click", function() {
2591-
if (selectedItemsFromOtherUser.length > 0) {
2592-
self.confirmActionOnOtherUsersChanges("commit");
2593-
} else {
2594-
var commitMessage = $('#commitMsg').val();
2595-
self.commit(commitMessage, $("#commitMsgDetail").val());
2596-
}
2597-
2591+
$.get("api/basic-and-default", function (data) {
2592+
var basicAndDefault = JSON.parse(data)["basic-and-default"]
2593+
if (basicAndDefault == "1") {
2594+
self.noCommitsOnDefault();
2595+
} else {
2596+
if (selectedItemsFromOtherUser.length > 0) {
2597+
self.confirmActionOnOtherUsersChanges("commit");
2598+
} else {
2599+
var commitMessage = $('#commitMsg').val();
2600+
self.commit(commitMessage, $("#commitMsgDetail").val());
2601+
}
2602+
}
2603+
})
25982604
});
25992605

26002606
$("#amendBtn").off("click");
@@ -2739,6 +2745,54 @@ webui.NewChangedFilesView = function(workspaceView) {
27392745
});
27402746
}
27412747

2748+
self.noCommitsOnDefault = function () {
2749+
function removePopup(popup) {
2750+
$(popup).children(".modal-fade").modal("hide");
2751+
$(".modal-backdrop").remove();
2752+
$("#noCommitsDefault").remove();
2753+
}
2754+
2755+
var popup = $(
2756+
'<div class="modal fade" tabindex="-1" id="noCommitsDefault" role="dialog" data-backdrop="static">' +
2757+
'<div class="modal-dialog modal-md" role="document">' +
2758+
'<div class="modal-content">' +
2759+
'<div class="modal-header">' +
2760+
'<h5 class="modal-title">Cannot commit to Default Branch</h5>' +
2761+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
2762+
'</div>' +
2763+
'<div class="modal-body">' +
2764+
'<div class="row">' +
2765+
'<div class="col-sm-1">' +
2766+
webui.warningIcon +
2767+
'</div>' +
2768+
'<div class="col-sm-11">' +
2769+
'<p>You cannot commit to the default merge branch while using basic mode. Please switch to another branch.</p>' +
2770+
'</div>' +
2771+
'</div>' +
2772+
'</div>' +
2773+
'<div class="modal-footer"></div>' +
2774+
'</div>' +
2775+
'</div>' +
2776+
'</div>'
2777+
)[0];
2778+
2779+
$("body").append(popup);
2780+
2781+
var popupFooter = $(".modal-footer", popup)[0];
2782+
webui.detachChildren(popupFooter);
2783+
2784+
$(
2785+
'<button class="btn btn-sm btn-secondary action-btn" id="noCommitDefaultButton">Ok</button>'
2786+
).appendTo(popupFooter);
2787+
2788+
$(popup).modal('show');
2789+
2790+
$("#noCommitsDefault").find(".close, #noCommitDefaultButton").click(function() {
2791+
removePopup(popup);
2792+
})
2793+
2794+
};
2795+
27422796
self.confirmActionOnOtherUsersChanges = function(action) {
27432797
function removeWarningModal(popup) {
27442798
$(popup).children(".modal-fade").modal("hide");

git-webui/src/share/git-webui/webui/js/git-webui.js

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,13 +2588,19 @@ webui.NewChangedFilesView = function(workspaceView) {
25882588
});
25892589
$("#commitBtn").off("click");
25902590
$("#commitBtn").on("click", function() {
2591-
if (selectedItemsFromOtherUser.length > 0) {
2592-
self.confirmActionOnOtherUsersChanges("commit");
2593-
} else {
2594-
var commitMessage = $('#commitMsg').val();
2595-
self.commit(commitMessage, $("#commitMsgDetail").val());
2596-
}
2597-
2591+
$.get("api/basic-and-default", function (data) {
2592+
var basicAndDefault = JSON.parse(data)["basic-and-default"]
2593+
if (basicAndDefault == "1") {
2594+
self.noCommitsOnDefault();
2595+
} else {
2596+
if (selectedItemsFromOtherUser.length > 0) {
2597+
self.confirmActionOnOtherUsersChanges("commit");
2598+
} else {
2599+
var commitMessage = $('#commitMsg').val();
2600+
self.commit(commitMessage, $("#commitMsgDetail").val());
2601+
}
2602+
}
2603+
})
25982604
});
25992605

26002606
$("#amendBtn").off("click");
@@ -2739,6 +2745,54 @@ webui.NewChangedFilesView = function(workspaceView) {
27392745
});
27402746
}
27412747

2748+
self.noCommitsOnDefault = function () {
2749+
function removePopup(popup) {
2750+
$(popup).children(".modal-fade").modal("hide");
2751+
$(".modal-backdrop").remove();
2752+
$("#noCommitsDefault").remove();
2753+
}
2754+
2755+
var popup = $(
2756+
'<div class="modal fade" tabindex="-1" id="noCommitsDefault" role="dialog" data-backdrop="static">' +
2757+
'<div class="modal-dialog modal-md" role="document">' +
2758+
'<div class="modal-content">' +
2759+
'<div class="modal-header">' +
2760+
'<h5 class="modal-title">Cannot commit to Default Branch</h5>' +
2761+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
2762+
'</div>' +
2763+
'<div class="modal-body">' +
2764+
'<div class="row">' +
2765+
'<div class="col-sm-1">' +
2766+
webui.warningIcon +
2767+
'</div>' +
2768+
'<div class="col-sm-11">' +
2769+
'<p>You cannot commit to the default merge branch while using basic mode. Please switch to another branch.</p>' +
2770+
'</div>' +
2771+
'</div>' +
2772+
'</div>' +
2773+
'<div class="modal-footer"></div>' +
2774+
'</div>' +
2775+
'</div>' +
2776+
'</div>'
2777+
)[0];
2778+
2779+
$("body").append(popup);
2780+
2781+
var popupFooter = $(".modal-footer", popup)[0];
2782+
webui.detachChildren(popupFooter);
2783+
2784+
$(
2785+
'<button class="btn btn-sm btn-secondary action-btn" id="noCommitDefaultButton">Ok</button>'
2786+
).appendTo(popupFooter);
2787+
2788+
$(popup).modal('show');
2789+
2790+
$("#noCommitsDefault").find(".close, #noCommitDefaultButton").click(function() {
2791+
removePopup(popup);
2792+
})
2793+
2794+
};
2795+
27422796
self.confirmActionOnOtherUsersChanges = function(action) {
27432797
function removeWarningModal(popup) {
27442798
$(popup).children(".modal-fade").modal("hide");

0 commit comments

Comments
 (0)