From e393fb8f3162a31c22b09eb8e3e2440e780963db Mon Sep 17 00:00:00 2001 From: dickeyxxx Date: Thu, 3 Dec 2015 15:10:37 -0800 Subject: [PATCH] display actual remote value in case it is modified with https://devcenter.heroku.com/articles/git#ssh-git-transport --- commands/git/remote.js | 3 ++- lib/git.js | 11 +++++++++++ test/mock/git.js | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/commands/git/remote.js b/commands/git/remote.js index ac97f7f..7f36908 100644 --- a/commands/git/remote.js +++ b/commands/git/remote.js @@ -23,7 +23,8 @@ function * run (context, heroku) { } else { yield git.exec(['remote', 'add', remote, url].concat(context.args)) } - cli.log(`set git remote ${cli.color.cyan(remote)} to ${cli.color.cyan(url)}`) + let newRemote = yield git.remoteUrl('heroku') + cli.log(`set git remote ${cli.color.cyan(remote)} to ${cli.color.cyan(newRemote)}`) } module.exports = { diff --git a/lib/git.js b/lib/git.js index ff5bc61..0728f4c 100644 --- a/lib/git.js +++ b/lib/git.js @@ -32,6 +32,16 @@ module.exports = function (context) { return `https://${context.httpGitHost}/${app}.git` } + function remoteUrl (name) { + return exec(['remote', '-v']) + .then(function (remotes) { + return remotes.split('\n') + .map((r) => r.split('\t')) + .find((r) => r[0] === name)[1] + .split(' ')[0] + }) + } + function url (app, ssh) { return ssh ? sshGitUrl(app) : httpGitUrl(app) } @@ -40,6 +50,7 @@ module.exports = function (context) { exec, spawn, remoteFromGitConfig, + remoteUrl, url } } diff --git a/test/mock/git.js b/test/mock/git.js index ea76704..9836d7c 100644 --- a/test/mock/git.js +++ b/test/mock/git.js @@ -3,6 +3,7 @@ module.exports = { remoteFromGitConfig: () => Promise.resolve('heroku'), url: (app) => `https://git.heroku.com/${app}.git`, + remoteUrl: () => Promise.resolve('https://git.heroku.com/myapp.git'), spawn: () => Promise.resolve(), exec: function (args) { switch (args.join(' ')) {