Skip to content

Commit 8caa52a

Browse files
committed
Push button only shows if there are changes to push
1 parent 0a9fc7d commit 8caa52a

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

CHANGELOG.md

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

88
## [2.2.1] - Unreleased
99

10+
### Added
11+
- Web UI includes a "Push Branch" button for local branches that are ahead of upstream
12+
1013
### Fixed
1114
- Studio export path doesn't get weird mixed slahes on Windows (#252)
1215

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ 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 + '">'
@@ -335,17 +338,19 @@ webui.SideBarView = function(mainView, noEventHandlers) {
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>'+
338-
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
341+
(canPush ? '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' : '')+
339342
'<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>'+
340343
'</div>'+
341344
'</div>').appendTo(collapseDiv);
342345
} else {
343346
$(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);
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+
}
349354
}
350355
} else {
351356
var refname = ref.replaceAll('/', '-');
@@ -754,7 +759,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
754759
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
755760
}
756761

757-
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");
758763
self.fetchSection($("#sidebar-remote-branches", self.element)[0], "Remote Branches", "remote-branches", "branch --remotes");
759764
self.fetchSection($("#sidebar-tags", self.element)[0], "Tags", "tags", "tag");
760765

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.2.2</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)