'pushing changes to git using node
I'm trying to commit and push changes using node without using any external npm packages
const { spawn,exec } = require('child_process');
const fs = require('fs');
const { stderr } = require('process');
(async ()=>{
if(fs.existsSync('./repo_dir'))
fs.rmSync('./repo_dir',{recursive:true});
exec(`git config --global --replace-all user.name "NAMEHERE" && git config --global --replace-all user.email "[email protected]" && git config --list`,(err,stdout,stderr)=>{
if(err)
console.log(`error: ${err}`);
if(stderr)
console.log(`stderr: ${stderr}`);
console.log(`stdout: ${stdout}`);
let git_spawn=spawn(`git`,[`clone`,`https://username:[email protected]/username/repo_dir.git`]);
git_spawn.stdout.on("data", data => {
console.log(`cloning stdout: ${data}`);
});
git_spawn.stderr.on("data", data => {
console.log(`cloning stderr: ${data}`);
});
git_spawn.on('error', (error) => {
console.log(`cloning error: ${error.message}`);
});
git_spawn.on("close", code => {
console.log(`child process exited with code ${code}`);
exec(`cd ./git_repo && touch blank.js && git add -A && git commit -m "updating" && git push && cd ..`,(err,stdout,stderr)=>{ //error somewhere here
console.log(`pushing error: ${err}`);
console.log(`pushing stdout: ${stdout}`);
console.log(`pushing stderr: ${stderr}`);
});
});
})
})();
but for some reason it doesn't work and I can't even pin point the error
output:
stdout: cloning stderr: Cloning into 'repo_dir'...
child process exited with code 0 pushing error: Error: Command failed: cd ./repo_dir && touch blank.js && git add -A && git commit -m "updating" && git push && cd ..
pushing stdout: On branch main Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
pushing stderr:
I'm guessing the problem is somewhere in committing and pushing
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
