Skip to content

Commit

Permalink
Push button only shows if there are changes to push
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-pbarton committed Jun 21, 2023
1 parent 0a9fc7d commit 8caa52a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.2.1] - Unreleased

### Added
- Web UI includes a "Push Branch" button for local branches that are ahead of upstream

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

Expand Down
21 changes: 13 additions & 8 deletions git-webui/src/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ webui.SideBarView = function(mainView, noEventHandlers) {
}
var cardDiv = $('<div class="card custom-card">').appendTo(accordionDiv)[0];
if (id.indexOf("local-branches") > -1) {
var refname = ref.substring(2);
// parses the output of git branch --verbose --verbose
var branchInfo = /^\*?\s*(?<branch_name>[\w-]+)\s+(?<hash>[^\s]+)\s+(?<remote>\[.*\])?.*/.exec(ref).groups;
var refname = branchInfo.branch_name;
var canPush = (branchInfo.remote === undefined) || (branchInfo.remote.includes("ahead")) // either no upstream or ahead of upstream
var itemId = refname + idPostfix;
var cardHeader = $('<div class="card-header" id="heading-' + itemId + '">').appendTo(cardDiv);
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 + '">'
Expand All @@ -335,17 +338,19 @@ webui.SideBarView = function(mainView, noEventHandlers) {
'<div class="d-grid gap-2 col-12 mx-auto">'+
'<button class="btn btn-xs btn-primary btn-block btn-checkout-local-branch mt-1">Checkout Branch</button>'+
'<button class="btn btn-xs btn-warning btn-block btn-merge-branch">Merge Branch</button>'+
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
(canPush ? '<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>' : '')+
'<button class="btn btn-xs btn-danger btn-block btn-delete-branch">Delete Branch</button>'+
'</div>'+
'</div>').appendTo(collapseDiv);
} else {
$(button).addClass("branch-current");
var cardBody = $('<div class="card-body">' +
'<div class="d-grid gap-2 col-12 mx-auto">'+
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
'</div>'+
'</div>').appendTo(collapseDiv);
if (canPush) {
var cardBody = $('<div class="card-body">' +
'<div class="d-grid gap-2 col-12 mx-auto">'+
'<button class="btn btn-xs btn-warning btn-block btn-push-branch">Push Branch</button>'+
'</div>'+
'</div>').appendTo(collapseDiv);
}
}
} else {
var refname = ref.replaceAll('/', '-');
Expand Down Expand Up @@ -754,7 +759,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
}

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

Expand Down
2 changes: 1 addition & 1 deletion module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Document name="git-source-control.ZPM">
<Module>
<Name>git-source-control</Name>
<Version>2.2.1</Version>
<Version>2.2.2</Version>
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
<Keywords>git source control studio vscode</Keywords>
<Packaging>module</Packaging>
Expand Down

0 comments on commit 8caa52a

Please sign in to comment.