问:我怎样才能跑步git push
from node.js
with passphrase
.
我正在尝试构建一个需要运行的小模块git push
from node.js
到远程repo
,但是当我使用 from 时出现错误node.js exec
但不是从终端。
My code.
./command.ts
import * as util from 'util';
const exec = util.promisify(require('child_process').exec);
export default function command(command: string): Promise<string> {
return exec(command, {cwd: process.cwd()}).then((resp) => {
const data = resp.stdout.toString().replace(/[\n\r]/g, '');
return Promise.resolve(data);
});
}
./index.ts
import command from './command';
async function init() {
try {
await command('git add .');
await command('git commit -m "my commit" ');
conat result = await command('git push');
} catch (e) {
console.log(e);
}
}
init();
当我跑步时ts-node ./index.ts
我收到以下错误。
Error: Command failed: git push
[email protected] /cdn-cgi/l/email-protection: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
但当我跑步时git push
从终端我得到密码提示,它起作用了。
关于如何解决这个问题的任何想法,有没有办法运行git push
与密码短语使用node.js
?
请记住,我很乐意在没有任何外部库的情况下解决这个问题。
提前致谢。