0

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");
0

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

I updated the answer based on your suggestion but now its throwing a different error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.