Skip to content

Commit d2fba37

Browse files
authored
Merge pull request #691 from intersystems/issue-586
Added revert / reset Head
2 parents c1d8963 + 2ba1f33 commit d2fba37

File tree

3 files changed

+201
-12
lines changed

3 files changed

+201
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111
- LoadProductionsFromDirectory method to help custom deployment scripts load decomposed productions from the repository (#670)
12+
- Added ability to reset head / revert most recent commit (#586)
1213

1314
### Fixed
1415
- 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
@@ -1105,10 +1105,10 @@ webui.LogView = function(historyView) {
11051105
streams = []
11061106
$(content).empty();
11071107
self.nextRef = ref;
1108-
self.populate();
1108+
self.populate(ref);
11091109
};
11101110

1111-
self.populate = function() {
1111+
self.populate = function(ref) {
11121112
var maxCount = 1000;
11131113
if (content.childElementCount > 0) {
11141114
// The last node is the 'Show more commits placeholder'. Remove it.
@@ -1127,8 +1127,7 @@ webui.LogView = function(historyView) {
11271127
}
11281128
var end = data.length;
11291129
}
1130-
1131-
var entry = new Entry(self, data.substring(start, end));
1130+
var entry = new Entry(self, data.substring(start, end), count == 0 ? true : false, ref);
11321131
content.appendChild(entry.element);
11331132
if (!self.lineHeight) {
11341133
self.lineHeight = Math.ceil($(entry.element).outerHeight() / 2) * 2;
@@ -1269,7 +1268,7 @@ webui.LogView = function(historyView) {
12691268
this.date.setUTCSeconds(parseInt(secs));
12701269
};
12711270

1272-
function Entry(logView, data) {
1271+
function Entry(logView, data, revert, ref) {
12731272
var self = this;
12741273

12751274
self.abbrevCommitHash = function() {
@@ -1286,13 +1285,20 @@ webui.LogView = function(historyView) {
12861285
};
12871286

12881287
self.createElement = function() {
1288+
var contents = "";
1289+
if (revert && (ref == 'HEAD' || ref == $('.branch-current').text())) {
1290+
contents = '<div style="overflow:hidden; display: flex"><p class="list-group-item-text"></p>' +
1291+
'<button type="button" class="btn btn-danger file-action-button" id="revertBtn" style="margin-left: 20px;">Revert</button></div>'
1292+
} else {
1293+
contents = '<p class="list-group-item-text"></p>'
1294+
}
12891295
self.element = $('<a class="log-entry list-group-item">' +
12901296
'<header>' +
12911297
'<h6></h6>' +
12921298
'<span class="log-entry-date">' + self.author.date.toLocaleString() + '&nbsp;</span> ' +
12931299
'<span class="badge">' + self.abbrevCommitHash() + '</span>' +
12941300
'</header>' +
1295-
'<p class="list-group-item-text"></p>' +
1301+
contents +
12961302
'</a>')[0];
12971303
$('<a target="_blank" href="mailto:' + self.author.email + '">' + self.author.name + '</a>').appendTo($("h6", self.element));
12981304
$(".list-group-item-text", self.element)[0].appendChild(document.createTextNode(self.abbrevMessage()));
@@ -1333,6 +1339,89 @@ webui.LogView = function(historyView) {
13331339
}
13341340
};
13351341

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

@@ -1363,6 +1452,11 @@ webui.LogView = function(historyView) {
13631452
self.message = self.message.trim();
13641453

13651454
self.createElement();
1455+
1456+
$("#revertBtn").off("click");
1457+
$("#revertBtn").on("click", function() {
1458+
self.chooseRevert();
1459+
});
13661460
};
13671461

13681462
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
@@ -1105,10 +1105,10 @@ webui.LogView = function(historyView) {
11051105
streams = []
11061106
$(content).empty();
11071107
self.nextRef = ref;
1108-
self.populate();
1108+
self.populate(ref);
11091109
};
11101110

1111-
self.populate = function() {
1111+
self.populate = function(ref) {
11121112
var maxCount = 1000;
11131113
if (content.childElementCount > 0) {
11141114
// The last node is the 'Show more commits placeholder'. Remove it.
@@ -1127,8 +1127,7 @@ webui.LogView = function(historyView) {
11271127
}
11281128
var end = data.length;
11291129
}
1130-
1131-
var entry = new Entry(self, data.substring(start, end));
1130+
var entry = new Entry(self, data.substring(start, end), count == 0 ? true : false, ref);
11321131
content.appendChild(entry.element);
11331132
if (!self.lineHeight) {
11341133
self.lineHeight = Math.ceil($(entry.element).outerHeight() / 2) * 2;
@@ -1269,7 +1268,7 @@ webui.LogView = function(historyView) {
12691268
this.date.setUTCSeconds(parseInt(secs));
12701269
};
12711270

1272-
function Entry(logView, data) {
1271+
function Entry(logView, data, revert, ref) {
12731272
var self = this;
12741273

12751274
self.abbrevCommitHash = function() {
@@ -1286,13 +1285,20 @@ webui.LogView = function(historyView) {
12861285
};
12871286

12881287
self.createElement = function() {
1288+
var contents = "";
1289+
if (revert && (ref == 'HEAD' || ref == $('.branch-current').text())) {
1290+
contents = '<div style="overflow:hidden; display: flex"><p class="list-group-item-text"></p>' +
1291+
'<button type="button" class="btn btn-danger file-action-button" id="revertBtn" style="margin-left: 20px;">Revert</button></div>'
1292+
} else {
1293+
contents = '<p class="list-group-item-text"></p>'
1294+
}
12891295
self.element = $('<a class="log-entry list-group-item">' +
12901296
'<header>' +
12911297
'<h6></h6>' +
12921298
'<span class="log-entry-date">' + self.author.date.toLocaleString() + '&nbsp;</span> ' +
12931299
'<span class="badge">' + self.abbrevCommitHash() + '</span>' +
12941300
'</header>' +
1295-
'<p class="list-group-item-text"></p>' +
1301+
contents +
12961302
'</a>')[0];
12971303
$('<a target="_blank" href="mailto:' + self.author.email + '">' + self.author.name + '</a>').appendTo($("h6", self.element));
12981304
$(".list-group-item-text", self.element)[0].appendChild(document.createTextNode(self.abbrevMessage()));
@@ -1333,6 +1339,89 @@ webui.LogView = function(historyView) {
13331339
}
13341340
};
13351341

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

@@ -1363,6 +1452,11 @@ webui.LogView = function(historyView) {
13631452
self.message = self.message.trim();
13641453

13651454
self.createElement();
1455+
1456+
$("#revertBtn").off("click");
1457+
$("#revertBtn").on("click", function() {
1458+
self.chooseRevert();
1459+
});
13661460
};
13671461

13681462
self.historyView = historyView;

0 commit comments

Comments
 (0)