Skip to content

Commit d32163b

Browse files
authored
Merge pull request #263 from isc-pbarton/push-button
Added push option to local branches in web UI
2 parents 67fbf79 + 8b44ec2 commit d32163b

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.2.1] - Unreleased
8+
## [2.3.0] - Unreleased
9+
10+
### Added
11+
- Web UI includes a "Push Branch" button for local branches that are ahead of upstream
912

1013
### Fixed
1114
- Studio export path doesn't get weird mixed slahes on Windows (#252)

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,19 +329,23 @@ webui.SideBarView = function(mainView, noEventHandlers) {
329329
+ refname
330330
+ '</button>').appendTo(cardHeader);
331331

332+
var collapseDiv = $('<div id="collapse-'+ itemId +'" class="accordion-collapse collapse" aria-labelledby="heading-' + itemId +'" data-parent="#accordion-'+id+'-'+idPostfix+'">').appendTo(cardDiv);
332333
if(ref[0] != "*") {
333-
var collapseDiv = $('<div id="collapse-'+ itemId +'" class="accordion-collapse collapse" aria-labelledby="heading-' + itemId +'" data-parent="#accordion-'+id+'-'+idPostfix+'">').appendTo(cardDiv);
334334
var cardBody = $('<div class="card-body">' +
335335
'<div class="d-grid gap-2 col-12 mx-auto">'+
336336
'<button class="btn btn-xs btn-primary btn-block btn-checkout-local-branch mt-1">Checkout Branch</button>'+
337337
'<button class="btn btn-xs btn-warning btn-block btn-merge-branch">Merge Branch</button>'+
338+
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
338339
'<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>'+
339340
'</div>'+
340341
'</div>').appendTo(collapseDiv);
341-
}
342-
343-
if (ref[0] == "*") {
342+
} else {
344343
$(button).addClass("branch-current");
344+
var cardBody = $('<div class="card-body">' +
345+
'<div class="d-grid gap-2 col-12 mx-auto">'+
346+
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
347+
'</div>'+
348+
'</div>').appendTo(collapseDiv);
345349
}
346350
} else {
347351
var refname = ref.replaceAll('/', '-');
@@ -642,6 +646,14 @@ webui.SideBarView = function(mainView, noEventHandlers) {
642646
webui.git("merge --no-commit --no-ff "+refName, "", self.upToDateHandler, callTestMergeHandler, callTestMergeHandler);
643647
}
644648

649+
/// pushes the selected local branch to "origin"
650+
self.pushBranch = function(e){
651+
e.preventDefault();
652+
var refName = $(this).parent().parent().parent().siblings(
653+
".card-header").children("button").html();
654+
webui.git(`push -u origin ${refName}`, "", self.upToDateHandler)
655+
}
656+
645657
self.goToSettingsPage = function() {
646658
window.location.replace(webui.settingsURL);
647659
}
@@ -667,7 +679,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
667679
$(self.buildAccordion(section, refs, id, undefined, "popup")).appendTo(popupContent);
668680
// Hide popup when the user selects a branch operation
669681
// Then execute the required operation with other even listeners
670-
$(popupContent).find(".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch, .btn-merge-remote-branch, .btn-merge-branch").click(function() {
682+
$(popupContent).find(".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch, .btn-merge-remote-branch, .btn-merge-branch, .btn-push-branch").click(function() {
671683
$(popup).modal('hide');
672684
});
673685
}
@@ -748,6 +760,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
748760

749761
if(!noEventHandlers){
750762
$(document).on('click', '.btn-checkout-local-branch', self.checkoutBranch);
763+
$(document).on('click', '.btn-push-branch', self.pushBranch);
751764
$(document).on('click', '.btn-checkout-remote-branch', self.checkoutBranch);
752765

753766
$(document).on('click', '.btn-delete-branch', self.deleteLocalBranch);

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,26 +322,35 @@ webui.SideBarView = function(mainView, noEventHandlers) {
322322
}
323323
var cardDiv = $('<div class="card custom-card">').appendTo(accordionDiv)[0];
324324
if (id.indexOf("local-branches") > -1) {
325-
var refname = ref.substring(2);
325+
// parses the output of git branch --verbose --verbose
326+
var branchInfo = /^\*?\s*(?<branch_name>[\w-]+)\s+(?<hash>[^\s]+)\s+(?<remote>\[.*\])?.*/.exec(ref).groups;
327+
var refname = branchInfo.branch_name;
328+
var canPush = (branchInfo.remote === undefined) || (branchInfo.remote.includes("ahead")) // either no upstream or ahead of upstream
326329
var itemId = refname + idPostfix;
327330
var cardHeader = $('<div class="card-header" id="heading-' + itemId + '">').appendTo(cardDiv);
328331
var button = $('<button class="btn btn-sm btn-default btn-branch text-left" type="button" data-toggle="collapse" data-target="#collapse-' + itemId + '" aria-expanded="true" aria-controls="collapse-' + itemId + '">'
329332
+ refname
330333
+ '</button>').appendTo(cardHeader);
331334

335+
var collapseDiv = $('<div id="collapse-'+ itemId +'" class="accordion-collapse collapse" aria-labelledby="heading-' + itemId +'" data-parent="#accordion-'+id+'-'+idPostfix+'">').appendTo(cardDiv);
332336
if(ref[0] != "*") {
333-
var collapseDiv = $('<div id="collapse-'+ itemId +'" class="accordion-collapse collapse" aria-labelledby="heading-' + itemId +'" data-parent="#accordion-'+id+'-'+idPostfix+'">').appendTo(cardDiv);
334337
var cardBody = $('<div class="card-body">' +
335338
'<div class="d-grid gap-2 col-12 mx-auto">'+
336339
'<button class="btn btn-xs btn-primary btn-block btn-checkout-local-branch mt-1">Checkout Branch</button>'+
337340
'<button class="btn btn-xs btn-warning btn-block btn-merge-branch">Merge Branch</button>'+
341+
(canPush ? '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' : '')+
338342
'<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>'+
339343
'</div>'+
340344
'</div>').appendTo(collapseDiv);
341-
}
342-
343-
if (ref[0] == "*") {
345+
} else {
344346
$(button).addClass("branch-current");
347+
if (canPush) {
348+
var cardBody = $('<div class="card-body">' +
349+
'<div class="d-grid gap-2 col-12 mx-auto">'+
350+
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
351+
'</div>'+
352+
'</div>').appendTo(collapseDiv);
353+
}
345354
}
346355
} else {
347356
var refname = ref.replaceAll('/', '-');
@@ -642,6 +651,14 @@ webui.SideBarView = function(mainView, noEventHandlers) {
642651
webui.git("merge --no-commit --no-ff "+refName, "", self.upToDateHandler, callTestMergeHandler, callTestMergeHandler);
643652
}
644653

654+
/// pushes the selected local branch to "origin"
655+
self.pushBranch = function(e){
656+
e.preventDefault();
657+
var refName = $(this).parent().parent().parent().siblings(
658+
".card-header").children("button").html();
659+
webui.git(`push -u origin ${refName}`, "", self.upToDateHandler)
660+
}
661+
645662
self.goToSettingsPage = function() {
646663
window.location.replace(webui.settingsURL);
647664
}
@@ -667,7 +684,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
667684
$(self.buildAccordion(section, refs, id, undefined, "popup")).appendTo(popupContent);
668685
// Hide popup when the user selects a branch operation
669686
// Then execute the required operation with other even listeners
670-
$(popupContent).find(".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch, .btn-merge-remote-branch, .btn-merge-branch").click(function() {
687+
$(popupContent).find(".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch, .btn-merge-remote-branch, .btn-merge-branch, .btn-push-branch").click(function() {
671688
$(popup).modal('hide');
672689
});
673690
}
@@ -742,12 +759,13 @@ webui.SideBarView = function(mainView, noEventHandlers) {
742759
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
743760
}
744761

745-
self.fetchSection($("#sidebar-local-branches", self.element)[0], "Local Branches", "local-branches", "branch");
762+
self.fetchSection($("#sidebar-local-branches", self.element)[0], "Local Branches", "local-branches", "branch --verbose --verbose");
746763
self.fetchSection($("#sidebar-remote-branches", self.element)[0], "Remote Branches", "remote-branches", "branch --remotes");
747764
self.fetchSection($("#sidebar-tags", self.element)[0], "Tags", "tags", "tag");
748765

749766
if(!noEventHandlers){
750767
$(document).on('click', '.btn-checkout-local-branch', self.checkoutBranch);
768+
$(document).on('click', '.btn-push-branch', self.pushBranch);
751769
$(document).on('click', '.btn-checkout-remote-branch', self.checkoutBranch);
752770

753771
$(document).on('click', '.btn-delete-branch', self.deleteLocalBranch);

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Document name="git-source-control.ZPM">
44
<Module>
55
<Name>git-source-control</Name>
6-
<Version>2.2.1</Version>
6+
<Version>2.3.0</Version>
77
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
88
<Keywords>git source control studio vscode</Keywords>
99
<Packaging>module</Packaging>

0 commit comments

Comments
 (0)