Last active
August 29, 2015 14:02
-
-
Save zheng1/5b121e2d9d0752512010 to your computer and use it in GitHub Desktop.
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
var exec = require('child_process').exec; | |
var child = exec('git remote -v',function(error, stdout, stderr) { | |
if (stderr) console.log('stderr: ' + stderr); | |
if (error) return console.log('exec error: ' + error); | |
var stdoutArr = stdout.split('\n'); | |
var remoteLine = stdoutArr[0].split('\t'); | |
var remoteName = remoteLine[0]; | |
if (remoteLine[1].indexOf('git@') !== 0) return console.log('this project do not need change'); | |
var remoteURL = remoteLine[1].replace('git@', 'http://').replace(/:/g, '/').replace('/', ':').split(' ')[0]; | |
var cmd = ['git remote set-url', remoteName, remoteURL, '&& git config --global credential.helper store'].join(' '); | |
exec(cmd); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment