Deno 运行 检查 Git 存储库状态
Deno run check Git repository status
我想使用 Deno 检查一些外部 git 存储库的状态。我发现 Deno.run
函数似乎是这种情况下的正确函数,所以我编写了这段代码片段来做到这一点:
const cmd = Deno.run({
cmd: ['git', '--git-dir="GIT_PATH/.git"', '--work-tree="GIT_PATH"', 'status', '--porcelain'],
stdout: "piped",
stderr: "piped"
});
const output = await cmd.output();
const outStr = new TextDecoder().decode(output);
console.log(outStr);
但是这个 returns 没什么,尽管如果我 运行 它在我的终端它 returns 信息就好了。我确实注意到这段代码片段工作正常并且 returns 正确的信息:
const cmd = Deno.run({
cmd: ['git', 'status', '--porcelain'],
stdout: "piped",
stderr: "piped"
});
const output = await cmd.output();
const outStr = new TextDecoder().decode(output);
console.log(outStr);
我也尝试在命令前添加 sudo(我知道,我知道)但这并没有解决任何问题:(
Deno.run
不会生成 shell 而是直接运行 git 命令。确保在最终代码中 GIT_PATH
周围没有双引号,因为这些是特殊的 shell 字符,您不希望在传递给 git 的最终参数中使用这些字符。
所以正确的代码是:
const cmd = Deno.run({
cmd: ['git', '--git-dir=GIT_PATH/.git', '--work-tree=GIT_PATH', 'status', '--porcelain'],
stdout: "piped",
stderr: "piped"
});
我想使用 Deno 检查一些外部 git 存储库的状态。我发现 Deno.run
函数似乎是这种情况下的正确函数,所以我编写了这段代码片段来做到这一点:
const cmd = Deno.run({
cmd: ['git', '--git-dir="GIT_PATH/.git"', '--work-tree="GIT_PATH"', 'status', '--porcelain'],
stdout: "piped",
stderr: "piped"
});
const output = await cmd.output();
const outStr = new TextDecoder().decode(output);
console.log(outStr);
但是这个 returns 没什么,尽管如果我 运行 它在我的终端它 returns 信息就好了。我确实注意到这段代码片段工作正常并且 returns 正确的信息:
const cmd = Deno.run({
cmd: ['git', 'status', '--porcelain'],
stdout: "piped",
stderr: "piped"
});
const output = await cmd.output();
const outStr = new TextDecoder().decode(output);
console.log(outStr);
我也尝试在命令前添加 sudo(我知道,我知道)但这并没有解决任何问题:(
Deno.run
不会生成 shell 而是直接运行 git 命令。确保在最终代码中 GIT_PATH
周围没有双引号,因为这些是特殊的 shell 字符,您不希望在传递给 git 的最终参数中使用这些字符。
所以正确的代码是:
const cmd = Deno.run({
cmd: ['git', '--git-dir=GIT_PATH/.git', '--work-tree=GIT_PATH', 'status', '--porcelain'],
stdout: "piped",
stderr: "piped"
});