Skip to content

Commit 89e3328

Browse files
authored
Merge pull request #536 from intersystems/issue-484
no Commits on default merge branch in basic mode
2 parents f0fe08b + 4e642e5 commit 89e3328

File tree

7 files changed

+193
-14
lines changed

7 files changed

+193
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Fixed
1616
- Fixed display of other users' username in workspace view on Unix (#530)
1717
- Fixed slowness loading some CSP pages with multiple instances sharing a webserver (#540)
18+
- Prevent direct commits to default merge branch in basic mode (#484)
1819

1920
## [2.6.0] - 2024-10-07
2021

cls/SourceControl/Git/Extension.cls

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
8181
quit $$$OK
8282
}
8383

84+
if (menuItemName = "Commit") {
85+
set defaultBasic = ##class(SourceControl.Git.Utils).InDefaultBranchBasicMode()
86+
if (defaultBasic) {
87+
Set Target = "WARNING: Please create a new branch before committing."
88+
set Action = 6
89+
quit $$$OK
90+
}
91+
}
92+
8493
if (menuItemName = "Commit") || (menuItemName = "Sync") {
8594
if ..CheckCommitterIdentity(settings, .Action, .Target) {
8695
quit $$$OK

cls/SourceControl/Git/Utils.cls

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ ClassMethod Sync(Msg As %String, Output alert As %String) As %Status
528528
if '..HasRemoteRepo() {
529529
write "No remote repository configured: skipping fetch, pull and push"
530530
do ..SyncCommit(Msg)
531+
} elseif ..InDefaultBranchBasicMode() {
532+
// Do not commit to default merge branch in basic mode
533+
write "In Basic mode on default merge branch: skipping commit and push"
534+
do ..Fetch()
535+
do ..Pull()
531536
} else {
532537
do ..Fetch()
533538
do ..Pull()
@@ -2832,4 +2837,16 @@ ClassMethod SetConfiguredRemote(url) As %String
28322837
quit output
28332838
}
28342839

2840+
// Returns true if the current branch is the default merge branch and we are in basic mode
2841+
2842+
ClassMethod InDefaultBranchBasicMode() As %Boolean
2843+
{
2844+
set basicMode = ..BasicMode()
2845+
set default = ..DefaultMergeBranch()
2846+
do ##class(SourceControl.Git.Utils).RunGitCommand("branch",.err,.out,"--show-current")
2847+
set current = out.ReadLine()
2848+
if (basicMode && (default = current)) { quit 1 }
2849+
quit 0
2850+
}
2851+
28352852
}

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
3232
set responseJSON = {
3333
"environment": (##class(SourceControl.Git.Utils).EnvironmentName())
3434
}
35+
} elseif $extract(pagePath, 6, *) = "basic-and-default" {
36+
set responseJSON = {
37+
"basic-and-default": (##class(SourceControl.Git.Utils).InDefaultBranchBasicMode())
38+
}
3539
} else {
3640
set %response.Status = ##class(%CSP.REST).#HTTP404NOTFOUND
3741
set responseJSON = {"error":("invalid URI: " _ pagePath)}

csp/sync.csp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@
5757
border-radius: 4px;
5858
}
5959

60+
/* The alert message box */
61+
.alert {
62+
padding: 20px;
63+
background-color: #f44336; /* Red */
64+
color: white;
65+
margin-bottom: 15px;
66+
}
67+
68+
/* The close button */
69+
.closebtn {
70+
margin-left: 15px;
71+
color: white;
72+
font-weight: bold;
73+
float: right;
74+
font-size: 22px;
75+
line-height: 20px;
76+
cursor: pointer;
77+
transition: 0.3s;
78+
}
79+
80+
/* When moving the mouse over the close button */
81+
.closebtn:hover {
82+
color: black;
83+
}
84+
85+
6086
</style>
6187
</head>
6288
<body>
@@ -83,6 +109,16 @@
83109
<h1 class="text-center">Sync Repository</h1>
84110
<div class="row">
85111
<div class="offset-sm-2 col-sm-8">
112+
<server>
113+
if ##class(SourceControl.Git.Utils).InDefaultBranchBasicMode() {
114+
&html<
115+
<div class = "alert">
116+
<span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span>
117+
<strong>Warning!</strong> Please change branches to make sure your changes are committed.
118+
</div>
119+
>
120+
}
121+
</server>
86122
<div style="display: #(fileSectionDisplay)#">
87123
<h3 class="section-header">Files to be committed with sync:</h3>
88124
<ul class="list-group">

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

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,13 +2598,20 @@ webui.NewChangedFilesView = function(workspaceView) {
25982598
});
25992599
$("#commitBtn").off("click");
26002600
$("#commitBtn").on("click", function() {
2601-
if (selectedItemsFromOtherUser.length > 0) {
2602-
self.confirmActionOnOtherUsersChanges("commit");
2603-
} else {
2604-
var commitMessage = $('#commitMsg').val();
2605-
self.commit(commitMessage, $("#commitMsgDetail").val());
2606-
}
2607-
2601+
// Make sure we are not commiting to default merge branch in basic mode
2602+
$.get("api/basic-and-default", function (data) {
2603+
var basicAndDefault = JSON.parse(data)["basic-and-default"]
2604+
if (basicAndDefault == "1") {
2605+
self.noCommitsOnDefault();
2606+
} else {
2607+
if (selectedItemsFromOtherUser.length > 0) {
2608+
self.confirmActionOnOtherUsersChanges("commit");
2609+
} else {
2610+
var commitMessage = $('#commitMsg').val();
2611+
self.commit(commitMessage, $("#commitMsgDetail").val());
2612+
}
2613+
}
2614+
})
26082615
});
26092616

26102617
$("#amendBtn").off("click");
@@ -2749,6 +2756,55 @@ webui.NewChangedFilesView = function(workspaceView) {
27492756
});
27502757
}
27512758

2759+
// Popup for when trying to commit to default merge branch in basic mode
2760+
self.noCommitsOnDefault = function () {
2761+
function removePopup(popup) {
2762+
$(popup).children(".modal-fade").modal("hide");
2763+
$(".modal-backdrop").remove();
2764+
$("#noCommitsDefault").remove();
2765+
}
2766+
2767+
var popup = $(
2768+
'<div class="modal fade" tabindex="-1" id="noCommitsDefault" role="dialog" data-backdrop="static">' +
2769+
'<div class="modal-dialog modal-md" role="document">' +
2770+
'<div class="modal-content">' +
2771+
'<div class="modal-header">' +
2772+
'<h5 class="modal-title">Cannot commit to Default Branch</h5>' +
2773+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
2774+
'</div>' +
2775+
'<div class="modal-body">' +
2776+
'<div class="row">' +
2777+
'<div class="col-sm-1">' +
2778+
webui.warningIcon +
2779+
'</div>' +
2780+
'<div class="col-sm-11">' +
2781+
'<p>You cannot commit directly to the default merge branch while using basic mode. Please switch to another branch.</p>' +
2782+
'</div>' +
2783+
'</div>' +
2784+
'</div>' +
2785+
'<div class="modal-footer"></div>' +
2786+
'</div>' +
2787+
'</div>' +
2788+
'</div>'
2789+
)[0];
2790+
2791+
$("body").append(popup);
2792+
2793+
var popupFooter = $(".modal-footer", popup)[0];
2794+
webui.detachChildren(popupFooter);
2795+
2796+
$(
2797+
'<button class="btn btn-sm btn-secondary action-btn" id="noCommitDefaultButton">Ok</button>'
2798+
).appendTo(popupFooter);
2799+
2800+
$(popup).modal('show');
2801+
2802+
$("#noCommitsDefault").find(".close, #noCommitDefaultButton").click(function() {
2803+
removePopup(popup);
2804+
})
2805+
2806+
};
2807+
27522808
self.confirmActionOnOtherUsersChanges = function(action) {
27532809
function removeWarningModal(popup) {
27542810
$(popup).children(".modal-fade").modal("hide");

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

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,13 +2598,20 @@ webui.NewChangedFilesView = function(workspaceView) {
25982598
});
25992599
$("#commitBtn").off("click");
26002600
$("#commitBtn").on("click", function() {
2601-
if (selectedItemsFromOtherUser.length > 0) {
2602-
self.confirmActionOnOtherUsersChanges("commit");
2603-
} else {
2604-
var commitMessage = $('#commitMsg').val();
2605-
self.commit(commitMessage, $("#commitMsgDetail").val());
2606-
}
2607-
2601+
// Make sure we are not commiting to default merge branch in basic mode
2602+
$.get("api/basic-and-default", function (data) {
2603+
var basicAndDefault = JSON.parse(data)["basic-and-default"]
2604+
if (basicAndDefault == "1") {
2605+
self.noCommitsOnDefault();
2606+
} else {
2607+
if (selectedItemsFromOtherUser.length > 0) {
2608+
self.confirmActionOnOtherUsersChanges("commit");
2609+
} else {
2610+
var commitMessage = $('#commitMsg').val();
2611+
self.commit(commitMessage, $("#commitMsgDetail").val());
2612+
}
2613+
}
2614+
})
26082615
});
26092616

26102617
$("#amendBtn").off("click");
@@ -2749,6 +2756,55 @@ webui.NewChangedFilesView = function(workspaceView) {
27492756
});
27502757
}
27512758

2759+
// Popup for when trying to commit to default merge branch in basic mode
2760+
self.noCommitsOnDefault = function () {
2761+
function removePopup(popup) {
2762+
$(popup).children(".modal-fade").modal("hide");
2763+
$(".modal-backdrop").remove();
2764+
$("#noCommitsDefault").remove();
2765+
}
2766+
2767+
var popup = $(
2768+
'<div class="modal fade" tabindex="-1" id="noCommitsDefault" role="dialog" data-backdrop="static">' +
2769+
'<div class="modal-dialog modal-md" role="document">' +
2770+
'<div class="modal-content">' +
2771+
'<div class="modal-header">' +
2772+
'<h5 class="modal-title">Cannot commit to Default Branch</h5>' +
2773+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
2774+
'</div>' +
2775+
'<div class="modal-body">' +
2776+
'<div class="row">' +
2777+
'<div class="col-sm-1">' +
2778+
webui.warningIcon +
2779+
'</div>' +
2780+
'<div class="col-sm-11">' +
2781+
'<p>You cannot commit directly to the default merge branch while using basic mode. Please switch to another branch.</p>' +
2782+
'</div>' +
2783+
'</div>' +
2784+
'</div>' +
2785+
'<div class="modal-footer"></div>' +
2786+
'</div>' +
2787+
'</div>' +
2788+
'</div>'
2789+
)[0];
2790+
2791+
$("body").append(popup);
2792+
2793+
var popupFooter = $(".modal-footer", popup)[0];
2794+
webui.detachChildren(popupFooter);
2795+
2796+
$(
2797+
'<button class="btn btn-sm btn-secondary action-btn" id="noCommitDefaultButton">Ok</button>'
2798+
).appendTo(popupFooter);
2799+
2800+
$(popup).modal('show');
2801+
2802+
$("#noCommitsDefault").find(".close, #noCommitDefaultButton").click(function() {
2803+
removePopup(popup);
2804+
})
2805+
2806+
};
2807+
27522808
self.confirmActionOnOtherUsersChanges = function(action) {
27532809
function removeWarningModal(popup) {
27542810
$(popup).children(".modal-fade").modal("hide");

0 commit comments

Comments
 (0)