Code Monkey home page Code Monkey logo

prepush-if-changed's Introduction

prepush-if-changed Build Status Coverage Status

Acts as a pre-push hook to run commands only if committed files match the specified glob.

Installation

Using npm

npm install --save-dev prepush-if-changed

Using yarn

yarn add -D prepush-if-changed

Why

It doesn't always make sense to run pre-push hooks on every push. Sometimes you need to trigger a hook only when the pushed changes affect a specific area of your file structure. This project contains a script that will check committed files against a glob and only trigger the task if there's a match.

The script will compare your current local branch with the remote(origin) one. If the remote branch does not exist the script will exit with code 0 without performing any execution.

Configuration

You are going to need a git hook management library. We'll use husky for this example.

A configuration like this will execute unit tests once you attempt to push changes of any js/jsx files inside the src folder

This example uses package.json for configuration.

// package.json
{
  "husky": {
    "hooks": {
      "pre-push": "prepush-if-changed"
    }
  },
  "prepush-if-changed": {
    "src/**/*.js?(x)": "npm run test"
  }
}

You can use the following files to write a config:

package.json,
.prepushrc,
.prepushrc.json,
.prepushrc.yaml,
.prepushrc.yml,
.prepushrc.js,
prepush.config.js,

Matching files

Your commands will be executed only if any of the committed files match the glob. prepush-if-changed uses micromatch for matching files.

prepush-if-changed's People

Contributors

dprovodnikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

javifm86

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.