代码拉取完成,页面将自动刷新
/*
* SimpleGit
* @author Dustan Kasten <dustan@skookum.com>
*/
var exec = require('child_process').exec;
var async = require('async');
var simplegit = {
currentBranch: 'master',
execute: function(action, cb) {
exec(action, function(err, stdout, stderr) {
if (err) throw err;
console.log(action);
console.log(stdout);
cb && cb();
});
},
add: function(files, cb) {
var files = files ? files.join(' ') : '.',
action = [ 'git', 'add', files ];
this.execute(action.join(' '), cb);
},
commit: function(message, cb) {
var message = message ? '"' + message + '"' : "Commit from nodeapp",
action = [ 'git', 'commit -m', message, '-a' ];
this.execute(action.join(' '), cb);
},
/* obj = {}
* action, remote, branch
*/
action: function(obj, cb) {
var obj = obj || {},
action = [ 'git',
obj.action || 'pull',
obj.remote || 'origin',
obj.branch || 'master'
];
this.execute(action.join(' '), cb);
},
pull: function(obj, cb) {
var obj = obj || {};
this.action({
action: 'pull',
remote: obj.remote || 'origin',
branch: obj.branch || simplegit.currentBranch || 'master'
}, cb);
},
push: function(obj, cb) {
var obj = obj || {};
this.action({
action: 'push',
remote: obj.remote || 'origin',
branch: obj.branch || simplegit.currentBranch || 'master'
}, cb);
},
'git-sync': function(data, callback) {
var self = this;
// clean up data for the git commands
data['add-files'] = data['add-files'] || null;
data['commit-message'] = data['commit-message'] || null;
async.series([
function add(cb) {
self.add(data['commit-files'], function() {
cb(null, 'add')
});
},
function commit(cb) {
self.commit(data['commit-message'], function() {
cb(null, 'commit')
});
},
function pull(cb) {
self.pull({}, function() {
cb(null, 'pull') }
);
},
function push(cb) {
self.push({}, function() {
cb(null, 'push')
});
},
],
function collectedCallback(err, results) {
if (err) {
err = {
"status": "error",
"message" : "Something went wrong syncing with Github. View developer logs to debug"
};
}
results = {
"status": "success",
"data": {
"message": "You have successfully sync’d with Github"
}
};
callback(err || results);
}
)
}
};
exec("git symbolic-ref -q HEAD", function(err, stdout, stderr) {
if (err) throw err;
var branch = stdout.split('/');
branch = branch[branch.length-1];
simplegit.currentBranch = branch;
});
module.exports = simplegit;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。