diff --git a/bin/gh-pages b/bin/gh-pages index 1496e93..e5305d3 100755 --- a/bin/gh-pages +++ b/bin/gh-pages @@ -15,6 +15,8 @@ program .option('-x, --silent', 'Do not output the repository url') .option('-b, --branch ', 'name of the branch you\'ll be pushing to', 'gh-pages') + .option('-o, --remote ', + 'The name of the remote', 'origin') .option('-m, --message ', 'commit message', 'Updates') .option('-t, --dotfiles', 'Include dotfiles') @@ -30,6 +32,7 @@ ghpages.publish(path.join(process.cwd(), program.dist), { message: program.message, dotfiles: !!program.dotfiles, add: !!program.add, + remote: program.remote, push: !program.noPush, logger: function(message) { process.stderr.write(message + '\n'); diff --git a/lib/git.js b/lib/git.js index af3c8b7..414e0bd 100644 --- a/lib/git.js +++ b/lib/git.js @@ -99,13 +99,14 @@ exports.clone = function clone(repo, dir, branch, options) { return Q.resolve(); } else { return fs.makeTree(path.dirname(path.resolve(dir))).then(function() { - var args = ['clone', repo, dir, '--branch', branch, '--single-branch']; + var args = ['clone', repo, dir, '--branch', branch, '--single-branch', + '--origin', options.remote]; if (options.depth) { args.push('--depth', options.depth); } return spawn(git, args).fail(function(err) { // try again without banch options - return spawn(git, ['clone', repo, dir]); + return spawn(git, ['clone', repo, dir, '--origin', options.remote]); }); }); } diff --git a/lib/index.js b/lib/index.js index 708467d..024191a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -29,9 +29,9 @@ function getRemoteUrl(dir, remote) { }) .fail(function(err) { return Q.reject(new Error( - 'Failed to get remote.origin.url (task must either be run in a ' + - 'git repository with a configured origin remote or must be ' + - 'configured with the "repo" option).')); + 'Failed to get remote.' + remote + '.url (task must either be ' + + 'run in a git repository with a configured ' + remote + ' remote ' + + 'or must be configured with the "repo" option).')); }); } @@ -39,7 +39,7 @@ function getRepo(options) { if (options.repo) { return Q.resolve(options.repo); } else { - return getRemoteUrl(process.cwd(), 'origin'); + return getRemoteUrl(process.cwd(), options.remote); } } diff --git a/readme.md b/readme.md index 5cbfde1..5256535 100644 --- a/readme.md +++ b/readme.md @@ -149,6 +149,24 @@ ghpages.publish(path.join(__dirname, 'build'), { ``` +#### options.remote + * type: `string` + * default: `'origin'` + +The name of the remote you'll be pushing to. The default is your `'origin'` remote, but this can be configured to push to any remote. + +Example use of the `remote` option: + +```js +/** + * This task pushes to the `gh-pages` branch of of your `upstream` remote. + */ +ghpages.publish(path.join(__dirname, 'build'), { + remote: 'upstream' +}, callback); +``` + + #### options.tag * type: `string` * default: `''`