Follow git standard when creating reverts

Context is in https://bugs.chromium.org/p/gerrit/issues/detail?id=4492

Change-Id: If6b93661de2a3225418b525dc8afdb1711f62928
This commit is contained in:
Ravi Mistry
2016-09-06 13:11:54 -04:00
parent 63d4913bc5
commit c1e675439a
2 changed files with 30 additions and 14 deletions

View File

@@ -36,18 +36,16 @@
populateRevertMessage: function(message) { populateRevertMessage: function(message) {
// Figure out what the revert title should be. // Figure out what the revert title should be.
var originalTitle = message.split('\n')[0]; var originalTitle = message.split('\n')[0];
var revertTitle = 'Revert of ' + originalTitle; var revertTitle = 'Revert "' + originalTitle + '"';
if (originalTitle.startsWith('Revert of ')) { // Figure out what the revert commit message should be.
revertTitle = 'Reland of ' + var commitRegex = /\n{1,2}\nChange-Id: (\w+)\n/gm;
originalTitle.substring('Revert of '.length); var match = commitRegex.exec(message);
} else if (originalTitle.startsWith('Reland of ')) { var revertCommitText = 'This reverts commit ' + match[1] + '.';
revertTitle = 'Revert of ' +
originalTitle.substring('Reland of '.length);
}
// Add '> ' in front of the original commit text. // Add '> ' in front of the original commit text.
var originalCommitText = message.replace(/^/gm, '> '); var originalCommitText = message.replace(/^/gm, '> ');
this.message = revertTitle + '\n\n' + this.message = revertTitle + '\n\n' +
revertCommitText + '\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n\n' + 'Reason for revert: <INSERT REASONING HERE>\n\n' +
'Original issue\'s description:\n' + originalCommitText; 'Original issue\'s description:\n' + originalCommitText;
}, },

View File

@@ -40,21 +40,39 @@ limitations under the License.
test('single line', function() { test('single line', function() {
assert.isNotOk(element.message); assert.isNotOk(element.message);
element.populateRevertMessage('one line commit'); element.populateRevertMessage('one line commit\n\nChange-Id: abcdefg\n');
var expected = 'Revert of one line commit\n\n' + var expected = 'Revert "one line commit"\n\n' +
'This reverts commit abcdefg.\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n\n' + 'Reason for revert: <INSERT REASONING HERE>\n\n' +
'Original issue\'s description:\n' + 'Original issue\'s description:\n' +
'> one line commit'; '> one line commit\n> \n' +
'> Change-Id: abcdefg\n> ';
assert.equal(element.message, expected); assert.equal(element.message, expected);
}); });
test('multi line', function() { test('multi line', function() {
assert.isNotOk(element.message); assert.isNotOk(element.message);
element.populateRevertMessage('many lines\ncommit\n\nmessage\n'); element.populateRevertMessage(
var expected = 'Revert of many lines\n\n' + 'many lines\ncommit\n\nmessage\n\nChange-Id: abcdefg\n');
var expected = 'Revert "many lines"\n\n' +
'This reverts commit abcdefg.\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n\n' + 'Reason for revert: <INSERT REASONING HERE>\n\n' +
'Original issue\'s description:\n' + 'Original issue\'s description:\n' +
'> many lines\n> commit\n> \n> message\n> '; '> many lines\n> commit\n> \n> message\n> \n' +
'> Change-Id: abcdefg\n> ';
assert.equal(element.message, expected);
});
test('revert a revert', function () {
assert.isNotOk(element.message);
element.populateRevertMessage(
'Revert "one line commit"\n\nChange-Id: abcdefg\n');
var expected = 'Revert "Revert "one line commit""\n\n' +
'This reverts commit abcdefg.\n\n' +
'Reason for revert: <INSERT REASONING HERE>\n\n' +
'Original issue\'s description:\n' +
'> Revert "one line commit"\n> \n' +
'> Change-Id: abcdefg\n> ';
assert.equal(element.message, expected); assert.equal(element.message, expected);
}); });
}); });