Merge pull request #61 from tschaub/custom-remote

Support a custom remote.
This commit is contained in:
Tim Schaub 2016-03-02 09:33:57 -07:00
commit 06238afaa6
4 changed files with 28 additions and 6 deletions

View file

@ -15,6 +15,8 @@ program
.option('-x, --silent', 'Do not output the repository url') .option('-x, --silent', 'Do not output the repository url')
.option('-b, --branch <branch>', .option('-b, --branch <branch>',
'name of the branch you\'ll be pushing to', 'gh-pages') 'name of the branch you\'ll be pushing to', 'gh-pages')
.option('-o, --remote <name>',
'The name of the remote', 'origin')
.option('-m, --message <message>', .option('-m, --message <message>',
'commit message', 'Updates') 'commit message', 'Updates')
.option('-t, --dotfiles', 'Include dotfiles') .option('-t, --dotfiles', 'Include dotfiles')
@ -30,6 +32,7 @@ ghpages.publish(path.join(process.cwd(), program.dist), {
message: program.message, message: program.message,
dotfiles: !!program.dotfiles, dotfiles: !!program.dotfiles,
add: !!program.add, add: !!program.add,
remote: program.remote,
push: !program.noPush, push: !program.noPush,
logger: function(message) { logger: function(message) {
process.stderr.write(message + '\n'); process.stderr.write(message + '\n');

View file

@ -99,13 +99,14 @@ exports.clone = function clone(repo, dir, branch, options) {
return Q.resolve(); return Q.resolve();
} else { } else {
return fs.makeTree(path.dirname(path.resolve(dir))).then(function() { 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) { if (options.depth) {
args.push('--depth', options.depth); args.push('--depth', options.depth);
} }
return spawn(git, args).fail(function(err) { return spawn(git, args).fail(function(err) {
// try again without banch options // try again without banch options
return spawn(git, ['clone', repo, dir]); return spawn(git, ['clone', repo, dir, '--origin', options.remote]);
}); });
}); });
} }

View file

@ -29,9 +29,9 @@ function getRemoteUrl(dir, remote) {
}) })
.fail(function(err) { .fail(function(err) {
return Q.reject(new Error( return Q.reject(new Error(
'Failed to get remote.origin.url (task must either be run in a ' + 'Failed to get remote.' + remote + '.url (task must either be ' +
'git repository with a configured origin remote or must be ' + 'run in a git repository with a configured ' + remote + ' remote ' +
'configured with the "repo" option).')); 'or must be configured with the "repo" option).'));
}); });
} }
@ -39,7 +39,7 @@ function getRepo(options) {
if (options.repo) { if (options.repo) {
return Q.resolve(options.repo); return Q.resolve(options.repo);
} else { } else {
return getRemoteUrl(process.cwd(), 'origin'); return getRemoteUrl(process.cwd(), options.remote);
} }
} }

View file

@ -149,6 +149,24 @@ ghpages.publish(path.join(__dirname, 'build'), {
``` ```
#### <a id="optionsremote">options.remote</a>
* 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);
```
#### <a id="optionstag">options.tag</a> #### <a id="optionstag">options.tag</a>
* type: `string` * type: `string`
* default: `''` * default: `''`