Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
git-add-remote/index.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (30 sloc)
945 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| var path = require('path'); | |
| var cp = require("child_process"); | |
| module.exports = function(dir) { | |
| var cwd = dir ? path.resolve(dir) : process.cwd(); | |
| function addRemote(name, url, cb) { | |
| if (typeof cb !== 'function') { | |
| throw new TypeError('expected callback to be a function'); | |
| } | |
| if (typeof url !== 'string') { | |
| cb(new TypeError('expected url to be a string')); | |
| return; | |
| } | |
| if (typeof name !== 'string') { | |
| cb(new TypeError('expected name to be a string')); | |
| return; | |
| } | |
| cp.exec('git remote add ' + name + ' ' + url, {cwd: cwd}, cb); | |
| }; | |
| addRemote.sync = function(name, url) { | |
| if (typeof url !== 'string') { | |
| throw new TypeError('expected url to be a string'); | |
| } | |
| if (typeof name !== 'string') { | |
| throw new TypeError('expected name to be a string'); | |
| } | |
| cp.execSync('git remote add ' + name + ' ' + url, {cwd: cwd}); | |
| }; | |
| return addRemote; | |
| }; |