steveukx / git-js

A light weight interface for running git commands in any node.js application.
MIT License
3.53k stars 318 forks source link

Ignoring or handling SIGINT #509

Open rarkins opened 4 years ago

rarkins commented 4 years ago

I have an app that uses this library, and the app has a handler in place to "gracefully" catch SIGINT and exit after the job it's working on is completed. However, it seems that git commands from simple-git are being interrupted and returning before work is complete. e.g. a clone or fetch.

My ideal is for simple-git/git to ignore the SIGINT, but otherwise I need it to fail in Node so that I can detect and exit out. Right now it seems to be interrupted but my app isn't aware.

Do you have any ideas for how to handle this? e.g. this answer on SO suggests shell: true could help but I'm not sure if that's compatible with how you run/parse git commands.

fsahmad commented 1 year ago

Having the same issue, I'm working on a tool that updates the git index, and I want to be able to catch the SIGINT signal to prevent corrupting the index. Because the git process is spawned in the same process group (same console window in windows land), the SIGINT signal is sent to all spawned processes and there's no way to "trap" it in the node.js process.

Being able to pass a spawn option detached: true (or shell: true) would solve this issue.

Is this feasible to add, or would it cause problems with the rest of the library?