Skip to content

Commit

Permalink
Fix file added already before discard
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-etamarch committed Jan 16, 2025
1 parent d37a062 commit 679ef41
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
27 changes: 19 additions & 8 deletions git-webui/release/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ webui.parseGitResponse = function(data) {
};
}

webui.processGitResponse = function(data, command, callback, warningCallback) {
webui.processGitResponse = function(data, command, callback, warningCallback,errorCallback) {
var result = webui.parseGitResponse(data);
var rcode = result.rcode;
var output = result.output;
Expand Down Expand Up @@ -177,15 +177,20 @@ webui.processGitResponse = function(data, command, callback, warningCallback) {
location.reload();
return false;
}
webui.showError(displayMessage);
if (errorCallback) {
errorCallback(displayMessage);
} else {
webui.showError(displayMessage);
}

//}
} else {
webui.showError("The command <pre>"+command.join(" ")+"</pre> failed because of an unknown reason. Returned response: \n\n"+data)
}
}
}

webui.git_command = function(command, callback, warningCallback) {
webui.git_command = function(command, callback, warningCallback, errorCallback) {
$.ajax({
url: "git-command",
type: "POST",
Expand All @@ -194,11 +199,15 @@ webui.git_command = function(command, callback, warningCallback) {
command: command
}),
success: function(data) {
webui.processGitResponse(data, command, callback, warningCallback);
webui.processGitResponse(data, command, callback, warningCallback, errorCallback);
},
error: function(data) {
var trimmedData = data.replace(/(\r\n)/gm, "\n");
webui.showError(trimmedData);
if (errorCallback) {
errorCallback(data.replace(/(\r\n)/gm, "\n"));
} else {
var trimmedData = data.replace(/(\r\n)/gm, "\n");
webui.showError(trimmedData);
}
},
});
}
Expand Down Expand Up @@ -3020,11 +3029,13 @@ webui.NewChangedFilesView = function(workspaceView) {
}

self.discard = function() {
webui.git_command(["add", "--"].concat(selectedItems), function() {
function restoreCommand(data) {
webui.git_command(["restore", "--staged", "--worktree", "--"].concat(selectedItems), function() {
workspaceView.update();
});
});
}
// We want to try to run restore even if add fails (since the file might have already been added)
webui.git_command(["add", "--"].concat(selectedItems), restoreCommand,undefined,restoreCommand);
}

self.amend = function(message, details) {
Expand Down
27 changes: 19 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 @@ -146,7 +146,7 @@ webui.parseGitResponse = function(data) {
};
}

webui.processGitResponse = function(data, command, callback, warningCallback) {
webui.processGitResponse = function(data, command, callback, warningCallback,errorCallback) {
var result = webui.parseGitResponse(data);
var rcode = result.rcode;
var output = result.output;
Expand Down Expand Up @@ -177,15 +177,20 @@ webui.processGitResponse = function(data, command, callback, warningCallback) {
location.reload();
return false;
}
webui.showError(displayMessage);
if (errorCallback) {
errorCallback(displayMessage);
} else {
webui.showError(displayMessage);
}

//}
} else {
webui.showError("The command <pre>"+command.join(" ")+"</pre> failed because of an unknown reason. Returned response: \n\n"+data)
}
}
}

webui.git_command = function(command, callback, warningCallback) {
webui.git_command = function(command, callback, warningCallback, errorCallback) {
$.ajax({
url: "git-command",
type: "POST",
Expand All @@ -194,11 +199,15 @@ webui.git_command = function(command, callback, warningCallback) {
command: command
}),
success: function(data) {
webui.processGitResponse(data, command, callback, warningCallback);
webui.processGitResponse(data, command, callback, warningCallback, errorCallback);
},
error: function(data) {
var trimmedData = data.replace(/(\r\n)/gm, "\n");
webui.showError(trimmedData);
if (errorCallback) {
errorCallback(data.replace(/(\r\n)/gm, "\n"));
} else {
var trimmedData = data.replace(/(\r\n)/gm, "\n");
webui.showError(trimmedData);
}
},
});
}
Expand Down Expand Up @@ -3020,11 +3029,13 @@ webui.NewChangedFilesView = function(workspaceView) {
}

self.discard = function() {
webui.git_command(["add", "--"].concat(selectedItems), function() {
function restoreCommand(data) {
webui.git_command(["restore", "--staged", "--worktree", "--"].concat(selectedItems), function() {
workspaceView.update();
});
});
}
// We want to try to run restore even if add fails (since the file might have already been added)
webui.git_command(["add", "--"].concat(selectedItems), restoreCommand,undefined,restoreCommand);
}

self.amend = function(message, details) {
Expand Down

0 comments on commit 679ef41

Please sign in to comment.