Merge "Patch optional commit field on CommitInfo response if missing"
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
index 9bcba8e..688cd0a 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
@@ -689,8 +689,8 @@
                 if (!change.reviewer_updates) {
                   change.reviewer_updates = null;
                 }
-                var currentRevision =
-                    change.revisions[this._getLatestRevisionSHA(change)];
+                var latestRevisionSha = this._getLatestRevisionSHA(change);
+                var currentRevision = change.revisions[latestRevisionSha];
                 if (currentRevision.commit && currentRevision.commit.message) {
                   this._latestCommitMessage = currentRevision.commit.message;
                 } else {
@@ -700,6 +700,10 @@
                 this._change = change;
                 if (!this._patchRange || !this._patchRange.patchNum ||
                     this._patchRange.patchNum === currentRevision._number) {
+                  // CommitInfo.commit is optional, and may need patching.
+                  if (!currentRevision.commit.commit) {
+                    currentRevision.commit.commit = latestRevisionSha;
+                  }
                   this._commitInfo = currentRevision.commit;
                   this._currentRevisionActions = currentRevision.actions;
                   // TODO: Fetch and process files.
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html
index 7c05c78..6b5849a 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html
@@ -498,6 +498,23 @@
       });
     });
 
+    test('commit sha is populated from getChangeDetail', function(done) {
+      sandbox.stub(element, '_changeChanged');
+      sandbox.stub(element.$.restAPI, 'getChangeDetail', function() {
+        return Promise.resolve({
+          id: '123456789',
+          labels: {},
+          current_revision: 'foo',
+          revisions: {foo: {commit: {}}},
+        });
+      });
+
+      element._getChangeDetail().then(function() {
+        assert.equal('foo', element._commitInfo.commit);
+        done();
+      });
+    });
+
     test('reply dialog focus can be controlled', function() {
       var FocusTarget = element.$.replyDialog.FocusTarget;
       var openSpy = sandbox.spy(element, '_openReplyDialog');