Node.js产生参数,导致git update-index失败

问题描述 投票:0回答:1

我具有运行git update-index的简单功能。

const gitUpdateIndex = (path, pattern) => {
  return new Promise((resolve, reject) => {
    const error = [];
    const opt = {
      cwd: path
    };
    const process = spawn("git", [`update-index --chmod=+x ${pattern}`], opt);
    process.on("close", () => {
      if (error.length > 0) {
        reject(error);
      }
      resolve();
    });
    process.stderr.on("data", data => error.push(data.toString().trim()));
  });
};

而且我想这样称呼-

await gitUpdateIndex(dirPath, "./*.sh");

但是这会引发错误-->

[
  "git: 'update-index --chmod=+x ./*.sh' is not a git command. See 'git --help'."
]

我有一个简单的函数来运行git update-index。 const gitUpdateIndex =(路径,模式)=> {返回新的Promise((解决,拒绝)=> {const error = []; const opt = {cwd:path ...

javascript node.js git ecmascript-6 spawn
1个回答
0
投票

您必须将每个参数定义为单独的数组元素:

© www.soinside.com 2019 - 2024. All rights reserved.