Soham Dasgupta
Soham Dasgupta

Reputation: 5199

Node.js spawn arguments causing git update-index to fail

I have a simple function to run git update-index.

exports.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()));
  });
};

And I am trying to call it like -

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

But this is throwing an error like -

[
  "Ignoring path *.sh\nfatal: git update-index: cannot chmod +x '*.sh'"
]

EDIT:

Seems like passing the absolute path to the function fixes it instead of an unix glob pattern.

await gitUpdateIndex(dirPath, "C:\\test\\hello.sh");

Upvotes: 0

Views: 50

Answers (1)

Felix Kling
Felix Kling

Reputation: 816384

You have to define every argument as individual array element:

spawn("git", ['update-index', '--chmod=+x', pattern], opt)

You are currently doing the equivalent to

git 'update-index --chmod=+x ./*.sh'

(note the quotes)

Upvotes: 1

Related Questions