diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
index 4506c1654f..3f5bd13e4a 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html
@@ -608,6 +608,7 @@ limitations under the License.
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 257a062358..6391d70065 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
@@ -136,6 +136,11 @@
},
/** @type {?} */
_commitInfo: Object,
+ _currentRevision: {
+ type: Object,
+ computed: '_computeCurrentRevision(_change.current_revision, ' +
+ '_change.revisions)',
+ },
_files: Object,
_changeNum: String,
_diffDrafts: {
@@ -1642,5 +1647,9 @@
this.$.restAPI.saveChangeStarred(e.detail.change._number,
e.detail.starred);
},
+
+ _computeCurrentRevision(currentRevision, revisions) {
+ return revisions && revisions[currentRevision];
+ },
});
})();
diff --git a/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.html b/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.html
index a9843a333f..792c300383 100644
--- a/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.html
+++ b/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.html
@@ -17,6 +17,7 @@ limitations under the License.
+
@@ -47,9 +48,12 @@ limitations under the License.
- Checkout this change locally and make your desired modifications to
- the files.
+ Checkout this change locally and make your desired modifications
+ to the files.
+
+
+
@@ -71,6 +75,7 @@ limitations under the License.
+
diff --git a/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.js b/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.js
index 548116c4c8..02d00cf714 100644
--- a/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog.js
@@ -20,6 +20,13 @@
const COMMIT_COMMAND = 'git add . && git commit --amend --no-edit';
const PUSH_COMMAND_PREFIX = 'git push origin HEAD:refs/for/';
+ // Command names correspond to download plugin definitions.
+ const PREFERRED_FETCH_COMMAND_ORDER = [
+ 'checkout',
+ 'cherry pick',
+ 'pull',
+ ];
+
Polymer({
is: 'gr-upload-help-dialog',
@@ -30,23 +37,83 @@
*/
properties: {
+ revision: Object,
targetBranch: String,
_commitCommand: {
type: String,
value: COMMIT_COMMAND,
readOnly: true,
},
+ _fetchCommand: {
+ type: String,
+ computed: '_computeFetchCommand(revision, ' +
+ '_preferredDownloadCommand, _preferredDownloadScheme)',
+ },
+ _preferredDownloadCommand: String,
+ _preferredDownloadScheme: String,
_pushCommand: {
type: String,
computed: '_computePushCommand(targetBranch)',
},
},
+ attached() {
+ this.$.restAPI.getLoggedIn().then(loggedIn => {
+ if (loggedIn) {
+ return this.$.restAPI.getPreferences();
+ }
+ }).then(prefs => {
+ if (prefs) {
+ this._preferredDownloadCommand = prefs.download_command;
+ this._preferredDownloadScheme = prefs.download_scheme;
+ }
+ });
+ },
+
_handleCloseTap(e) {
e.preventDefault();
this.fire('close', null, {bubbles: false});
},
+ _computeFetchCommand(revision, preferredDownloadCommand,
+ preferredDownloadScheme) {
+ if (!revision) { return; }
+ if (!revision || !revision.fetch) { return; }
+
+ let scheme = preferredDownloadScheme;
+ if (!scheme) {
+ const keys = Object.keys(revision.fetch).sort();
+ if (keys.length === 0) {
+ return;
+ }
+ scheme = keys[0];
+ }
+
+ if (!revision.fetch[scheme] || !revision.fetch[scheme].commands) {
+ return;
+ }
+
+ const cmds = {};
+ Object.entries(revision.fetch[scheme].commands).forEach(([key, cmd]) => {
+ cmds[key.toLowerCase()] = cmd;
+ });
+
+ if (preferredDownloadCommand &&
+ cmds[preferredDownloadCommand.toLowerCase()]) {
+ return cmds[preferredDownloadCommand.toLowerCase()];
+ }
+
+ // If no supported command preference is given, look for known commands
+ // from the downloads plugin in order of preference.
+ for (let i = 0; i < PREFERRED_FETCH_COMMAND_ORDER.length; i++) {
+ if (cmds[PREFERRED_FETCH_COMMAND_ORDER[i]]) {
+ return cmds[PREFERRED_FETCH_COMMAND_ORDER[i]];
+ }
+ }
+
+ return undefined;
+ },
+
_computePushCommand(targetBranch) {
return PUSH_COMMAND_PREFIX + targetBranch;
},
diff --git a/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog_test.html b/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog_test.html
index 60fe3e6ca5..a5a6e7698f 100644
--- a/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog_test.html
+++ b/polygerrit-ui/app/elements/change/gr-upload-help-dialog/gr-upload-help-dialog_test.html
@@ -48,5 +48,67 @@ limitations under the License.
assert.equal(element._pushCommand,
'git push origin HEAD:refs/for/master');
});
+
+ suite('fetch command', () => {
+ const testRev = {
+ fetch: {
+ http: {
+ commands: {
+ Checkout: 'http checkout',
+ Pull: 'http pull',
+ },
+ },
+ ssh: {
+ commands: {
+ Pull: 'ssh pull',
+ },
+ },
+ },
+ };
+
+ test('null cases', () => {
+ assert.isUndefined(element._computeFetchCommand());
+ assert.isUndefined(element._computeFetchCommand({}));
+ assert.isUndefined(element._computeFetchCommand({fetch: null}));
+ assert.isUndefined(element._computeFetchCommand({fetch: {}}));
+ });
+
+ test('insufficiently defined scheme', () => {
+ assert.isUndefined(
+ element._computeFetchCommand(testRev, undefined, 'badscheme'));
+
+ const rev = Object.assign({}, testRev);
+ rev.fetch = Object.assign({}, testRev.fetch, {nocmds: {commands: {}}});
+ assert.isUndefined(
+ element._computeFetchCommand(rev, undefined, 'nocmds'));
+
+ rev.fetch.nocmds.commands.unsupported = 'unsupported';
+ assert.isUndefined(
+ element._computeFetchCommand(rev, undefined, 'nocmds'));
+ });
+
+ test('default scheme and command', () => {
+ const cmd = element._computeFetchCommand(testRev);
+ assert.isTrue(cmd === 'http checkout' || cmd === 'ssh pull');
+ });
+
+ test('default command', () => {
+ assert.strictEqual(
+ element._computeFetchCommand(testRev, undefined, 'http'),
+ 'http checkout');
+ assert.strictEqual(
+ element._computeFetchCommand(testRev, undefined, 'ssh'),
+ 'ssh pull');
+ });
+
+ test('user preferred scheme and command', () => {
+ assert.strictEqual(
+ element._computeFetchCommand(testRev, 'PULL', 'http'),
+ 'http pull');
+ assert.strictEqual(
+ element._computeFetchCommand(testRev, 'badcmd', 'http'),
+ 'http checkout');
+ });
+ });
});