Skip to content

Commit 3bfadf6

Browse files
authored
Fix error message substring (#43)
* Confirmation alert pops up when the user presses delete branch button * Added icon to alert * Committing logging to test error messaging on checkout * Committing logging to test error messaging on checkout * The error messages now display correctly. See code comments. Co-authored-by: Sarmishta Velury <[email protected]>
1 parent d943a26 commit 3bfadf6

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ webui.git = function(cmd, arg1, arg2) {
7777
var fIndex = data.length;
7878
while (true) {
7979
var oldFIndex = fIndex;
80-
var fIndex = data.lastIndexOf("\r\n", fIndex - 1);
80+
fIndex = data.lastIndexOf("\r\n", fIndex - 1);
8181
var line = data.substring(fIndex + 2, oldFIndex);
8282
if (line.length > 0) {
8383
var footer = line.split(": ");
@@ -86,17 +86,25 @@ webui.git = function(cmd, arg1, arg2) {
8686
break;
8787
}
8888
}
89+
// Trims the the data variable to remove the footers extracted in the loop.
90+
// Windows adds \r\n for every line break but the Git-Stderr-Length variable,
91+
// counts it as only one character, throwing off the message length.
92+
var trimmedData = data.substring(0, fIndex).replace(/(\r\n)/gm, "\n");
93+
var fIndex = trimmedData.length
8994

90-
var messageStartIndex = fIndex - parseInt(footers["Git-Stderr-Length"]) -1;
91-
var message = data.substring(messageStartIndex, fIndex);
92-
var output = data.substring(0, messageStartIndex);
95+
var messageLength = parseInt(footers["Git-Stderr-Length"]);
96+
var messageStartIndex = fIndex-messageLength;
97+
var message = trimmedData.substring(messageStartIndex, fIndex);
98+
99+
var output = trimmedData.substring(0, messageStartIndex);
93100
var rcode = parseInt(footers["Git-Return-Code"]);
101+
94102
if (rcode == 0) {
95103
if (callback) {
96104
callback(output);
97105
}
98106
// Return code is 0 but there is stderr output: this is a warning message
99-
if (message.length > 1) {
107+
if (message.length > 0) {
100108
webui.showWarning(message);
101109
}
102110
} else {
@@ -1823,8 +1831,6 @@ $(function () {
18231831
var refName = $(this).parent().parent().parent().siblings(
18241832
".card-header").children("button").html();
18251833

1826-
console.log($(this).parent().parent().parent()[0]);
1827-
18281834
var popup = $( '<div class="modal fade" id="confirm-branch-delete" role="dialog">' +
18291835
'<div class="modal-dialog modal-md">' +
18301836
'<div class="modal-content">' +

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ webui.git = function(cmd, arg1, arg2) {
7777
var fIndex = data.length;
7878
while (true) {
7979
var oldFIndex = fIndex;
80-
var fIndex = data.lastIndexOf("\r\n", fIndex - 1);
80+
fIndex = data.lastIndexOf("\r\n", fIndex - 1);
8181
var line = data.substring(fIndex + 2, oldFIndex);
8282
if (line.length > 0) {
8383
var footer = line.split(": ");
@@ -86,17 +86,25 @@ webui.git = function(cmd, arg1, arg2) {
8686
break;
8787
}
8888
}
89+
// Trims the the data variable to remove the footers extracted in the loop.
90+
// Windows adds \r\n for every line break but the Git-Stderr-Length variable,
91+
// counts it as only one character, throwing off the message length.
92+
var trimmedData = data.substring(0, fIndex).replace(/(\r\n)/gm, "\n");
93+
var fIndex = trimmedData.length
8994

90-
var messageStartIndex = fIndex - parseInt(footers["Git-Stderr-Length"]) -1;
91-
var message = data.substring(messageStartIndex, fIndex);
92-
var output = data.substring(0, messageStartIndex);
95+
var messageLength = parseInt(footers["Git-Stderr-Length"]);
96+
var messageStartIndex = fIndex-messageLength;
97+
var message = trimmedData.substring(messageStartIndex, fIndex);
98+
99+
var output = trimmedData.substring(0, messageStartIndex);
93100
var rcode = parseInt(footers["Git-Return-Code"]);
101+
94102
if (rcode == 0) {
95103
if (callback) {
96104
callback(output);
97105
}
98106
// Return code is 0 but there is stderr output: this is a warning message
99-
if (message.length > 1) {
107+
if (message.length > 0) {
100108
webui.showWarning(message);
101109
}
102110
} else {
@@ -1823,8 +1831,6 @@ $(function () {
18231831
var refName = $(this).parent().parent().parent().siblings(
18241832
".card-header").children("button").html();
18251833

1826-
console.log($(this).parent().parent().parent()[0]);
1827-
18281834
var popup = $( '<div class="modal fade" id="confirm-branch-delete" role="dialog">' +
18291835
'<div class="modal-dialog modal-md">' +
18301836
'<div class="modal-content">' +

0 commit comments

Comments
 (0)