|
| 1 | +diff --git a/lib/git.js b/lib/git.js |
| 2 | +index d4c5724272d00bd1f0d76c47dab47d21ccd094d9..3457c7c0fa30ee8294396ce1d3ef723ed838da93 100644 |
| 3 | +--- a/lib/git.js |
| 4 | ++++ b/lib/git.js |
| 5 | +@@ -199,8 +199,7 @@ Git.prototype.push = function (remote, branch, force) { |
| 6 | + * @return {Promise<string>} A promise for the remote URL. |
| 7 | + */ |
| 8 | + Git.prototype.getRemoteUrl = function (remote) { |
| 9 | +- return this.exec('config', '--get', 'remote.' + remote + '.url') |
| 10 | +- .then((git) => { |
| 11 | ++ const cleanOutput = (git) => { |
| 12 | + const repo = git.output && git.output.split(/[\n\r]/).shift(); |
| 13 | + if (repo) { |
| 14 | + return repo; |
| 15 | +@@ -209,7 +208,9 @@ Git.prototype.getRemoteUrl = function (remote) { |
| 16 | + 'Failed to get repo URL from options or current directory.', |
| 17 | + ); |
| 18 | + } |
| 19 | +- }) |
| 20 | ++ }; |
| 21 | ++ const pullURL = this.exec('config', '--get', 'remote.' + remote + '.url') |
| 22 | ++ .then(cleanOutput) |
| 23 | + .catch((err) => { |
| 24 | + throw new Error( |
| 25 | + 'Failed to get remote.' + |
| 26 | +@@ -221,6 +222,7 @@ Git.prototype.getRemoteUrl = function (remote) { |
| 27 | + 'or must be configured with the "repo" option).', |
| 28 | + ); |
| 29 | + }); |
| 30 | ++ return Promise.all([pullURL, this.exec('config', '--get', 'remote.' + remote + '.pushurl').then(cleanOutput).catch(() => pullURL)]); |
| 31 | + }; |
| 32 | + |
| 33 | + /** |
| 34 | +@@ -235,7 +237,7 @@ Git.prototype.deleteRef = function (branch) { |
| 35 | + |
| 36 | + /** |
| 37 | + * Clone a repo into the given dir if it doesn't already exist. |
| 38 | +- * @param {string} repo Repository URL. |
| 39 | ++ * @param {[string, string]} repo Repository URL. |
| 40 | + * @param {string} dir Target directory. |
| 41 | + * @param {string} branch Branch name. |
| 42 | + * @param {options} options All options. |
| 43 | +@@ -249,7 +251,7 @@ Git.clone = function clone(repo, dir, branch, options) { |
| 44 | + return fs.mkdirp(path.dirname(path.resolve(dir))).then(() => { |
| 45 | + const args = [ |
| 46 | + 'clone', |
| 47 | +- repo, |
| 48 | ++ repo[0], |
| 49 | + dir, |
| 50 | + '--branch', |
| 51 | + branch, |
| 52 | +@@ -264,14 +266,17 @@ Git.clone = function clone(repo, dir, branch, options) { |
| 53 | + // try again without branch or depth options |
| 54 | + return spawn(options.git, [ |
| 55 | + 'clone', |
| 56 | +- repo, |
| 57 | ++ repo[0], |
| 58 | + dir, |
| 59 | + '--origin', |
| 60 | + options.remote, |
| 61 | + ]); |
| 62 | + }) |
| 63 | + .then(() => new Git(dir, options.git)); |
| 64 | +- }); |
| 65 | ++ }).then(repo[0] !== repo[1] ? |
| 66 | ++ (g) => spawn(options.git, ['remote', 'set-url', '--push', options.remote, repo[1]], dir).then(() => g) : |
| 67 | ++ undefined |
| 68 | ++ ); |
| 69 | + } |
| 70 | + }); |
| 71 | + }; |
| 72 | +diff --git a/lib/index.js b/lib/index.js |
| 73 | +index 7b1365b89f96cdb97be12c534215ea390b04ce1a..fbb7a5fc0c6107860e48787294b84884f509732e 100644 |
| 74 | +--- a/lib/index.js |
| 75 | ++++ b/lib/index.js |
| 76 | +@@ -132,13 +132,13 @@ exports.publish = function publish(basePath, config, callback) { |
| 77 | + getRepo(options) |
| 78 | + .then((repo) => { |
| 79 | + repoUrl = repo; |
| 80 | +- const clone = getCacheDir(repo); |
| 81 | +- log('Cloning %s into %s', repo, clone); |
| 82 | ++ const clone = getCacheDir(repo[0]); |
| 83 | ++ log('Cloning %s into %s', repo[0], clone); |
| 84 | + return Git.clone(repo, clone, options.branch, options); |
| 85 | + }) |
| 86 | + .then((git) => { |
| 87 | + return git.getRemoteUrl(options.remote).then((url) => { |
| 88 | +- if (url !== repoUrl) { |
| 89 | ++ if (url[0] !== repoUrl[0] || url[1] !== repoUrl[1]) { |
| 90 | + const message = |
| 91 | + 'Remote url mismatch. Got "' + |
| 92 | + url + |
0 commit comments