Skip to content

Checkout branch name with slash via Web UI no longer fails #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Deletion of files in locked environment is now suppressed (#302)
- Failed to import file VS Code popup no longer shows up after overwriting file on server once (#264)
- Don't automatically stage files added to source control (#303)
- Checkout of branches whose names contain slashes via Web UI no longer fails (#295)

## [2.3.0] - 2023-12-06

Expand Down
61 changes: 43 additions & 18 deletions git-webui/release/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ webui.SideBarView = function(mainView, noEventHandlers) {
var cardDiv = $('<div class="card custom-card">').appendTo(accordionDiv)[0];
if (id.indexOf("local-branches") > -1) {
// parses the output of git branch --verbose --verbose
var matches = /^\*?\s*([\w-]+)\s+([^\s]+)\s+(\[.*\])?.*/.exec(ref);
var matches = /^\*?\s*([\w-\/]+)\s+([^\s]+)\s+(\[.*\])?.*/.exec(ref);
var branchInfo = {
"branch_name": matches[1],
"hash": matches[2],
"remote": matches[3]
}
var refname = branchInfo.branch_name;
var canPush = (branchInfo.remote === undefined) || (branchInfo.remote.indexOf("ahead") > -1) // either no upstream or ahead of upstream
var itemId = refname + idPostfix;
var itemId = refname.replaceAll('/', '-') + 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 + '">'
+ refname
Expand Down Expand Up @@ -479,16 +479,12 @@ webui.SideBarView = function(mainView, noEventHandlers) {
webui.git("fetch --prune",updateSideBar);
}

self.checkoutBranch = function(e) {
e.preventDefault();
$("#confirm-branch-checkout").remove();

var refName = $(this).parent().parent().parent().siblings(
".card-header").children("button").html();
self.checkoutBranch = function(branchType, refName) {
$("#confirm-branch-checkout").remove();

var remoteName = refName.split("/")[0];
var branchName = refName.split("/")[1];

var branchName = refName.split("/").slice(1).join("/");
var flag = 0;
webui.git("status -u --porcelain", function(data) {
$.get("api/uncommitted", function (uncommitted) {
Expand Down Expand Up @@ -534,12 +530,18 @@ webui.SideBarView = function(mainView, noEventHandlers) {
$("#confirm-branch-checkout").on('click', '#confirm-checkout', function(e){
e.preventDefault();
var refName = $("#confirm-branch-checkout pre")[0].innerHTML;
var remoteName = refName.split("/")[0];
var branchName = refName.split("/")[1];

if(branchName){
if(branchType === "remote"){
var remoteName = refName.split("/")[0];
var branchName = refName.split("/")[1];
webui.git("fetch "+remoteName+" "+branchName);
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
webui.git("branch -l "+branchName, function(existingBranch) {
if (existingBranch.length > 0) {
webui.git("checkout " +branchName, updateSideBar);
} else {
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
}
});
}
else{
webui.git("checkout " + refName, updateSideBar, "", "", webui.showSuccess);
Expand All @@ -552,11 +554,16 @@ webui.SideBarView = function(mainView, noEventHandlers) {
});
}
else{
if(branchName){
if(branchType === "remote"){
webui.git("fetch "+remoteName+" "+branchName);
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
webui.git("branch -l "+branchName, function(existingBranch) {
if (existingBranch.length > 0) {
webui.git("checkout " +branchName, updateSideBar);
} else {
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
}
});
}

else{
webui.git("checkout " + refName, updateSideBar, "", "", webui.showSuccess);
}
Expand All @@ -565,6 +572,24 @@ webui.SideBarView = function(mainView, noEventHandlers) {
});
}

self.checkoutLocalBranch = function(e) {
e.preventDefault();

var refName = $(this).parent().parent().parent().siblings(
".card-header").children("button").html();

self.checkoutBranch("local", refName);
}

self.checkoutRemoteBranch = function(e) {
e.preventDefault();

var refName = $(this).parent().parent().parent().siblings(
".card-header").children("button").html();

self.checkoutBranch("remote", refName);
}

self.deleteLocalBranch = function(e) {
e.preventDefault();

Expand Down Expand Up @@ -779,9 +804,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
self.fetchSection($("#sidebar-tags", self.element)[0], "Tags", "tags", "tag");

if(!noEventHandlers){
$(document).on('click', '.btn-checkout-local-branch', self.checkoutBranch);
$(document).on('click', '.btn-checkout-local-branch', self.checkoutLocalBranch);
$(document).on('click', '.btn-push-branch', self.pushBranch);
$(document).on('click', '.btn-checkout-remote-branch', self.checkoutBranch);
$(document).on('click', '.btn-checkout-remote-branch', self.checkoutRemoteBranch);

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

Expand Down
61 changes: 43 additions & 18 deletions git-webui/src/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ webui.SideBarView = function(mainView, noEventHandlers) {
var cardDiv = $('<div class="card custom-card">').appendTo(accordionDiv)[0];
if (id.indexOf("local-branches") > -1) {
// parses the output of git branch --verbose --verbose
var matches = /^\*?\s*([\w-]+)\s+([^\s]+)\s+(\[.*\])?.*/.exec(ref);
var matches = /^\*?\s*([\w-\/]+)\s+([^\s]+)\s+(\[.*\])?.*/.exec(ref);
var branchInfo = {
"branch_name": matches[1],
"hash": matches[2],
"remote": matches[3]
}
var refname = branchInfo.branch_name;
var canPush = (branchInfo.remote === undefined) || (branchInfo.remote.indexOf("ahead") > -1) // either no upstream or ahead of upstream
var itemId = refname + idPostfix;
var itemId = refname.replaceAll('/', '-') + 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 + '">'
+ refname
Expand Down Expand Up @@ -479,16 +479,12 @@ webui.SideBarView = function(mainView, noEventHandlers) {
webui.git("fetch --prune",updateSideBar);
}

self.checkoutBranch = function(e) {
e.preventDefault();
$("#confirm-branch-checkout").remove();

var refName = $(this).parent().parent().parent().siblings(
".card-header").children("button").html();
self.checkoutBranch = function(branchType, refName) {
$("#confirm-branch-checkout").remove();

var remoteName = refName.split("/")[0];
var branchName = refName.split("/")[1];

var branchName = refName.split("/").slice(1).join("/");
var flag = 0;
webui.git("status -u --porcelain", function(data) {
$.get("api/uncommitted", function (uncommitted) {
Expand Down Expand Up @@ -534,12 +530,18 @@ webui.SideBarView = function(mainView, noEventHandlers) {
$("#confirm-branch-checkout").on('click', '#confirm-checkout', function(e){
e.preventDefault();
var refName = $("#confirm-branch-checkout pre")[0].innerHTML;
var remoteName = refName.split("/")[0];
var branchName = refName.split("/")[1];

if(branchName){
if(branchType === "remote"){
var remoteName = refName.split("/")[0];
var branchName = refName.split("/")[1];
webui.git("fetch "+remoteName+" "+branchName);
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
webui.git("branch -l "+branchName, function(existingBranch) {
if (existingBranch.length > 0) {
webui.git("checkout " +branchName, updateSideBar);
} else {
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
}
});
}
else{
webui.git("checkout " + refName, updateSideBar, "", "", webui.showSuccess);
Expand All @@ -552,11 +554,16 @@ webui.SideBarView = function(mainView, noEventHandlers) {
});
}
else{
if(branchName){
if(branchType === "remote"){
webui.git("fetch "+remoteName+" "+branchName);
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
webui.git("branch -l "+branchName, function(existingBranch) {
if (existingBranch.length > 0) {
webui.git("checkout " +branchName, updateSideBar);
} else {
webui.git("checkout -b " +branchName + " " + refName, updateSideBar);
}
});
}

else{
webui.git("checkout " + refName, updateSideBar, "", "", webui.showSuccess);
}
Expand All @@ -565,6 +572,24 @@ webui.SideBarView = function(mainView, noEventHandlers) {
});
}

self.checkoutLocalBranch = function(e) {
e.preventDefault();

var refName = $(this).parent().parent().parent().siblings(
".card-header").children("button").html();

self.checkoutBranch("local", refName);
}

self.checkoutRemoteBranch = function(e) {
e.preventDefault();

var refName = $(this).parent().parent().parent().siblings(
".card-header").children("button").html();

self.checkoutBranch("remote", refName);
}

self.deleteLocalBranch = function(e) {
e.preventDefault();

Expand Down Expand Up @@ -779,9 +804,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
self.fetchSection($("#sidebar-tags", self.element)[0], "Tags", "tags", "tag");

if(!noEventHandlers){
$(document).on('click', '.btn-checkout-local-branch', self.checkoutBranch);
$(document).on('click', '.btn-checkout-local-branch', self.checkoutLocalBranch);
$(document).on('click', '.btn-push-branch', self.pushBranch);
$(document).on('click', '.btn-checkout-remote-branch', self.checkoutBranch);
$(document).on('click', '.btn-checkout-remote-branch', self.checkoutRemoteBranch);

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

Expand Down