Skip to content

Commit 0e3cac8

Browse files
committed
Added revert / reset Head
1 parent 4f1f989 commit 0e3cac8

File tree

4 files changed

+205
-14
lines changed

4 files changed

+205
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.9.1] - Unreleased
8+
## [2.10.0] - Unreleased
9+
10+
### Added
11+
- Added ability to reset head / revert most recent commit (#586)
912

1013
### Fixed
1114
- Fixed not showing warnings on Studio (#660)

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

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,10 @@ webui.LogView = function(historyView) {
10961096
streams = []
10971097
$(content).empty();
10981098
self.nextRef = ref;
1099-
self.populate();
1099+
self.populate(ref);
11001100
};
11011101

1102-
self.populate = function() {
1102+
self.populate = function(ref) {
11031103
var maxCount = 1000;
11041104
if (content.childElementCount > 0) {
11051105
// The last node is the 'Show more commits placeholder'. Remove it.
@@ -1118,8 +1118,7 @@ webui.LogView = function(historyView) {
11181118
}
11191119
var end = data.length;
11201120
}
1121-
1122-
var entry = new Entry(self, data.substring(start, end));
1121+
var entry = new Entry(self, data.substring(start, end), count == 0 ? true : false, ref);
11231122
content.appendChild(entry.element);
11241123
if (!self.lineHeight) {
11251124
self.lineHeight = Math.ceil($(entry.element).outerHeight() / 2) * 2;
@@ -1260,7 +1259,7 @@ webui.LogView = function(historyView) {
12601259
this.date.setUTCSeconds(parseInt(secs));
12611260
};
12621261

1263-
function Entry(logView, data) {
1262+
function Entry(logView, data, revert, ref) {
12641263
var self = this;
12651264

12661265
self.abbrevCommitHash = function() {
@@ -1277,13 +1276,20 @@ webui.LogView = function(historyView) {
12771276
};
12781277

12791278
self.createElement = function() {
1279+
var contents = "";
1280+
if (revert && (ref == 'HEAD' || ref == $('.branch-current').text())) {
1281+
contents = '<div style="overflow:hidden; display: flex"><p class="list-group-item-text"></p>' +
1282+
'<button type="button" class="btn btn-danger file-action-button" id="revertBtn" style="margin-left: 20px;">Revert</button></div>'
1283+
} else {
1284+
contents = '<p class="list-group-item-text"></p>'
1285+
}
12801286
self.element = $('<a class="log-entry list-group-item">' +
12811287
'<header>' +
12821288
'<h6></h6>' +
12831289
'<span class="log-entry-date">' + self.author.date.toLocaleString() + '&nbsp;</span> ' +
12841290
'<span class="badge">' + self.abbrevCommitHash() + '</span>' +
12851291
'</header>' +
1286-
'<p class="list-group-item-text"></p>' +
1292+
contents +
12871293
'</a>')[0];
12881294
$('<a target="_blank" href="mailto:' + self.author.email + '">' + self.author.name + '</a>').appendTo($("h6", self.element));
12891295
$(".list-group-item-text", self.element)[0].appendChild(document.createTextNode(self.abbrevMessage()));
@@ -1324,6 +1330,89 @@ webui.LogView = function(historyView) {
13241330
}
13251331
};
13261332

1333+
self.chooseRevert = function() {
1334+
function removePopup(popup) {
1335+
$(popup).children(".modal-fade").modal("hide");
1336+
$(".modal-backdrop").remove();
1337+
$("#chooseRevert").remove();
1338+
}
1339+
1340+
function confirmRevert(type) {
1341+
if (type == 'revert') {
1342+
webui.git_command(["revert", "--no-commit","HEAD"], function(output) {
1343+
webui.showSuccess(output);
1344+
workspaceView.update();
1345+
});
1346+
} else if (type == 'hardReset') {
1347+
webui.git_command(["reset", "--hard", "HEAD~1"], function(output) {
1348+
webui.showSuccess(output);
1349+
workspaceView.update();
1350+
});
1351+
}
1352+
1353+
}
1354+
1355+
var popup = $(
1356+
'<div class="modal fade" tabindex="-1" id="chooseRevert" role="dialog" data-backdrop="static">' +
1357+
'<div class="modal-dialog modal-md" role="document">' +
1358+
'<div class="modal-content">' +
1359+
'<div class="modal-header">' +
1360+
'<h5 class="modal-title">Choose Revert Type</h5>' +
1361+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
1362+
'</div>' +
1363+
'<div class="modal-body">' +
1364+
'<div class="row">' +
1365+
'<div class="col-sm-1">' +
1366+
webui.warningIcon +
1367+
'</div>' +
1368+
'<div class="col-sm-11">' +
1369+
'<p>There are a few options available to revert the previous commit. Please read the description carefully to make sure you choose'+
1370+
' the correct option.</p>' +
1371+
'<h4>Revert</h2><p><i>git revert --no-commit</i> - This will create a new change, which will be the reversal of the previous commit.'+
1372+
'It will not be autometically committed, so you can inspect/modify/combine the changes with others before you commit.</p>' +
1373+
'<h4>Hard Reset</h2><p><i>git reset --hard HEAD~1</i> - This will delete the previous commit entirely, and reset you to a state' +
1374+
' before the commit. <b>WARNING:</b> This will also delete <b>all uncommitted changes</b>, so make sure you have no changes left before' +
1375+
' attempting this operation.</p>' +
1376+
'</div>' +
1377+
'</div>' +
1378+
'</div>' +
1379+
'<div class="modal-footer"></div>' +
1380+
'</div>' +
1381+
'</div>' +
1382+
'</div>'
1383+
)[0];
1384+
1385+
$("body").append(popup);
1386+
1387+
var popupFooter = $(".modal-footer", popup)[0];
1388+
webui.detachChildren(popupFooter);
1389+
1390+
$(
1391+
'<button class="btn btn-sm btn-warning action-btn" id="revertNoCommitBtn">Revert</button>' +
1392+
'<button class="btn btn-sm btn-warning action-btn" id="hardResetBtn">Hard Reset</button>' +
1393+
'<button class="btn btn-sm btn-secondary action-btn" id="cancelRevertBtn">Cancel</button>'
1394+
).appendTo(popupFooter);
1395+
1396+
$(popup).modal('show');
1397+
1398+
$("#revertNoCommitBtn").on('click', function() {
1399+
removePopup(popup);
1400+
confirmRevert("revert");
1401+
});
1402+
1403+
$("#hardResetBtn").on('click', function() {
1404+
removePopup(popup);
1405+
confirmRevert("hardReset");
1406+
});
1407+
1408+
1409+
1410+
$("#chooseRevert").find(".close, #cancelRevertBtn").click(function() {
1411+
removePopup(popup);
1412+
})
1413+
};
1414+
1415+
13271416
self.parents = [];
13281417
self.message = ""
13291418

@@ -1354,6 +1443,11 @@ webui.LogView = function(historyView) {
13541443
self.message = self.message.trim();
13551444

13561445
self.createElement();
1446+
1447+
$("#revertBtn").off("click");
1448+
$("#revertBtn").on("click", function() {
1449+
self.chooseRevert();
1450+
});
13571451
};
13581452

13591453
self.historyView = historyView;

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

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,10 @@ webui.LogView = function(historyView) {
10961096
streams = []
10971097
$(content).empty();
10981098
self.nextRef = ref;
1099-
self.populate();
1099+
self.populate(ref);
11001100
};
11011101

1102-
self.populate = function() {
1102+
self.populate = function(ref) {
11031103
var maxCount = 1000;
11041104
if (content.childElementCount > 0) {
11051105
// The last node is the 'Show more commits placeholder'. Remove it.
@@ -1118,8 +1118,7 @@ webui.LogView = function(historyView) {
11181118
}
11191119
var end = data.length;
11201120
}
1121-
1122-
var entry = new Entry(self, data.substring(start, end));
1121+
var entry = new Entry(self, data.substring(start, end), count == 0 ? true : false, ref);
11231122
content.appendChild(entry.element);
11241123
if (!self.lineHeight) {
11251124
self.lineHeight = Math.ceil($(entry.element).outerHeight() / 2) * 2;
@@ -1260,7 +1259,7 @@ webui.LogView = function(historyView) {
12601259
this.date.setUTCSeconds(parseInt(secs));
12611260
};
12621261

1263-
function Entry(logView, data) {
1262+
function Entry(logView, data, revert, ref) {
12641263
var self = this;
12651264

12661265
self.abbrevCommitHash = function() {
@@ -1277,13 +1276,20 @@ webui.LogView = function(historyView) {
12771276
};
12781277

12791278
self.createElement = function() {
1279+
var contents = "";
1280+
if (revert && (ref == 'HEAD' || ref == $('.branch-current').text())) {
1281+
contents = '<div style="overflow:hidden; display: flex"><p class="list-group-item-text"></p>' +
1282+
'<button type="button" class="btn btn-danger file-action-button" id="revertBtn" style="margin-left: 20px;">Revert</button></div>'
1283+
} else {
1284+
contents = '<p class="list-group-item-text"></p>'
1285+
}
12801286
self.element = $('<a class="log-entry list-group-item">' +
12811287
'<header>' +
12821288
'<h6></h6>' +
12831289
'<span class="log-entry-date">' + self.author.date.toLocaleString() + '&nbsp;</span> ' +
12841290
'<span class="badge">' + self.abbrevCommitHash() + '</span>' +
12851291
'</header>' +
1286-
'<p class="list-group-item-text"></p>' +
1292+
contents +
12871293
'</a>')[0];
12881294
$('<a target="_blank" href="mailto:' + self.author.email + '">' + self.author.name + '</a>').appendTo($("h6", self.element));
12891295
$(".list-group-item-text", self.element)[0].appendChild(document.createTextNode(self.abbrevMessage()));
@@ -1324,6 +1330,89 @@ webui.LogView = function(historyView) {
13241330
}
13251331
};
13261332

1333+
self.chooseRevert = function() {
1334+
function removePopup(popup) {
1335+
$(popup).children(".modal-fade").modal("hide");
1336+
$(".modal-backdrop").remove();
1337+
$("#chooseRevert").remove();
1338+
}
1339+
1340+
function confirmRevert(type) {
1341+
if (type == 'revert') {
1342+
webui.git_command(["revert", "--no-commit","HEAD"], function(output) {
1343+
webui.showSuccess(output);
1344+
workspaceView.update();
1345+
});
1346+
} else if (type == 'hardReset') {
1347+
webui.git_command(["reset", "--hard", "HEAD~1"], function(output) {
1348+
webui.showSuccess(output);
1349+
workspaceView.update();
1350+
});
1351+
}
1352+
1353+
}
1354+
1355+
var popup = $(
1356+
'<div class="modal fade" tabindex="-1" id="chooseRevert" role="dialog" data-backdrop="static">' +
1357+
'<div class="modal-dialog modal-md" role="document">' +
1358+
'<div class="modal-content">' +
1359+
'<div class="modal-header">' +
1360+
'<h5 class="modal-title">Choose Revert Type</h5>' +
1361+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
1362+
'</div>' +
1363+
'<div class="modal-body">' +
1364+
'<div class="row">' +
1365+
'<div class="col-sm-1">' +
1366+
webui.warningIcon +
1367+
'</div>' +
1368+
'<div class="col-sm-11">' +
1369+
'<p>There are a few options available to revert the previous commit. Please read the description carefully to make sure you choose'+
1370+
' the correct option.</p>' +
1371+
'<h4>Revert</h2><p><i>git revert --no-commit</i> - This will create a new change, which will be the reversal of the previous commit.'+
1372+
'It will not be autometically committed, so you can inspect/modify/combine the changes with others before you commit.</p>' +
1373+
'<h4>Hard Reset</h2><p><i>git reset --hard HEAD~1</i> - This will delete the previous commit entirely, and reset you to a state' +
1374+
' before the commit. <b>WARNING:</b> This will also delete <b>all uncommitted changes</b>, so make sure you have no changes left before' +
1375+
' attempting this operation.</p>' +
1376+
'</div>' +
1377+
'</div>' +
1378+
'</div>' +
1379+
'<div class="modal-footer"></div>' +
1380+
'</div>' +
1381+
'</div>' +
1382+
'</div>'
1383+
)[0];
1384+
1385+
$("body").append(popup);
1386+
1387+
var popupFooter = $(".modal-footer", popup)[0];
1388+
webui.detachChildren(popupFooter);
1389+
1390+
$(
1391+
'<button class="btn btn-sm btn-warning action-btn" id="revertNoCommitBtn">Revert</button>' +
1392+
'<button class="btn btn-sm btn-warning action-btn" id="hardResetBtn">Hard Reset</button>' +
1393+
'<button class="btn btn-sm btn-secondary action-btn" id="cancelRevertBtn">Cancel</button>'
1394+
).appendTo(popupFooter);
1395+
1396+
$(popup).modal('show');
1397+
1398+
$("#revertNoCommitBtn").on('click', function() {
1399+
removePopup(popup);
1400+
confirmRevert("revert");
1401+
});
1402+
1403+
$("#hardResetBtn").on('click', function() {
1404+
removePopup(popup);
1405+
confirmRevert("hardReset");
1406+
});
1407+
1408+
1409+
1410+
$("#chooseRevert").find(".close, #cancelRevertBtn").click(function() {
1411+
removePopup(popup);
1412+
})
1413+
};
1414+
1415+
13271416
self.parents = [];
13281417
self.message = ""
13291418

@@ -1354,6 +1443,11 @@ webui.LogView = function(historyView) {
13541443
self.message = self.message.trim();
13551444

13561445
self.createElement();
1446+
1447+
$("#revertBtn").off("click");
1448+
$("#revertBtn").on("click", function() {
1449+
self.chooseRevert();
1450+
});
13571451
};
13581452

13591453
self.historyView = historyView;

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.9.1</Version>
6+
<Version>2.10.0</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)