I have a few Git repositories that get updated automatically by a script. One of the tasks of the script is to run npm install for every repository (the repositories contain Node.js projects).
From time to time this results in an updated package-lock.json file, and I would like to commit it automatically if it was changed.
Of course I can simply run:
git add package-lock.json
git commit -m 'Update dependencies.'
But this fails, if the file was not updated: While git add simply does nothing and exits with return code 0, the git commit call fails with exit code 1. How can I do this in a way that this only happens if the file was actually updated?
In other words: If the file was not updated, I do not want the git add/git commit part to happen. How could I do this?