我想用 child_process 从 nodeJS git pull、commit 和 push - 这假设可行吗?
var cmd = require('child_process');
var commmandString = "cd c:\\xampp\\htdocs\\MenuMakerServer\\experiments\\editormenu && git commit -am 'menu.json changes' && git push origin main";
cmd.exec(commmandString , function (error: any, stdout, stderr) {
if (error) {
callback(error.stack, null);
}
});
编辑:
好的,我设法让它工作:
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
var options = {cwd:"c:\\xampp\\htdocs\\MenuMakerServer\\projects\\editormenu"};
exec("git status && git pull && git commit -am 'menu changed' && git push", options, puts);