Merge "Support implicit PARENT parameter when calculating commitRange"
This commit is contained in:
@@ -568,13 +568,19 @@
|
||||
promises.push(this._getChangeDetail(this._changeNum).then(change => {
|
||||
let commit;
|
||||
let baseCommit;
|
||||
for (const k in change.revisions) {
|
||||
if (!change.revisions.hasOwnProperty(k)) continue;
|
||||
const patchNum = change.revisions[k]._number.toString();
|
||||
for (const commitSha in change.revisions) {
|
||||
if (!change.revisions.hasOwnProperty(commitSha)) continue;
|
||||
const revision = change.revisions[commitSha];
|
||||
const patchNum = revision._number.toString();
|
||||
if (patchNum === this._patchRange.patchNum) {
|
||||
commit = k;
|
||||
commit = commitSha;
|
||||
const commitObj = revision.commit || {};
|
||||
const parents = commitObj.parents || [];
|
||||
if (this._patchRange.basePatchNum === PARENT && parents.length) {
|
||||
baseCommit = parents[parents.length - 1].commit;
|
||||
}
|
||||
} else if (patchNum === this._patchRange.basePatchNum) {
|
||||
baseCommit = k;
|
||||
baseCommit = commitSha;
|
||||
}
|
||||
}
|
||||
this._commitRange = {commit, baseCommit};
|
||||
|
||||
@@ -622,6 +622,66 @@ limitations under the License.
|
||||
assert.equal(select.nativeSelect.value, 'SIDE_BY_SIDE');
|
||||
});
|
||||
|
||||
suite('_commitRange', () => {
|
||||
setup(() => {
|
||||
sandbox.stub(element.$.diff, 'reload');
|
||||
sandbox.stub(element, '_initCursor');
|
||||
sandbox.stub(element, '_getChangeDetail').returns(Promise.resolve({
|
||||
_number: 42,
|
||||
revisions: {
|
||||
'commit-sha-1': {
|
||||
_number: 1,
|
||||
commit: {
|
||||
parents: [{commit: 'sha-1-parent'}],
|
||||
},
|
||||
},
|
||||
'commit-sha-2': {_number: 2},
|
||||
'commit-sha-3': {_number: 3},
|
||||
'commit-sha-4': {_number: 4},
|
||||
'commit-sha-5': {
|
||||
_number: 5,
|
||||
commit: {
|
||||
parents: [{commit: 'sha-5-parent'}],
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
test('uses the patchNum and basePatchNum ', done => {
|
||||
element.params = {
|
||||
view: Gerrit.Nav.View.DIFF,
|
||||
changeNum: '42',
|
||||
patchNum: '4',
|
||||
basePatchNum: '2',
|
||||
path: '/COMMIT_MSG',
|
||||
};
|
||||
flush(() => {
|
||||
assert.deepEqual(element._commitRange, {
|
||||
baseCommit: 'commit-sha-2',
|
||||
commit: 'commit-sha-4',
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('uses the parent when there is no base patch num ', done => {
|
||||
element.params = {
|
||||
view: Gerrit.Nav.View.DIFF,
|
||||
changeNum: '42',
|
||||
patchNum: '5',
|
||||
path: '/COMMIT_MSG',
|
||||
};
|
||||
flush(() => {
|
||||
assert.deepEqual(element._commitRange, {
|
||||
commit: 'commit-sha-5',
|
||||
baseCommit: 'sha-5-parent',
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('_initCursor', () => {
|
||||
assert.isNotOk(element.$.cursor.initialLineNumber);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user