DEV Community

Chris Cook
Chris Cook

Posted on • Updated on

New Version of git-pull-run

It's been a while since I published my article on Automatically Install NPM Dependencies on Git Pull. After receiving a lot of positive feedback, I put all that stuff into an NPM package that automatically checks for changes and runs commands or scripts if there are any.

git-pull-run - npm

Run commands and scripts after git pull. Latest version: 1.4.0, last published: 10 months ago. Start using git-pull-run in your project by running `npm i git-pull-run`. There are no other projects in the npm registry using git-pull-run.

favicon npmjs.com

The package must be integrated with Husky to be executed during the post-merge git hook. A pattern must be specified to match files when pulling changes. If any change matches the specified pattern, the provided command or script will be executed automatically.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# matches the package-lock.json inside project directory
# executes command npm install
# runs script post-merge 
npx git-pull-run -p "package-lock.json" -c "npm install" -s "post-merge"
Enter fullscreen mode Exit fullscreen mode

This executes the npm install command and runs the npm run post-merge script and prints the following output to the console.

Image description

Recently I received an issue on my GitHub repository with a request to print a message on the console if changes were found during the git pull. This was already possible with the command option -c 'echo "message"', but can be quite tricky because the quotes have to be escaped properly. Today I released a new version that enables this feature natively with a dedicated message option.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# matches only the package-lock.json inside project directory
# prints message to the console
npx git-pull-run -p "package-lock.json" -m "Some packages were changed. Run 'npm i' to update your dependencies"
Enter fullscreen mode Exit fullscreen mode

This prints the specified message to the console when git changes are pulled, and does not execute any commands or scripts.

Image description

I hope this package might be useful to someone and would appreciate your feedback and opinion.

Top comments (0)