Skip to content

Instantly share code, notes, and snippets.

@betorobson
Forked from sindresorhus/post-merge
Last active January 10, 2022 13:13
Show Gist options
  • Select an option

  • Save betorobson/23e5914b51e844bac5eaa6032d6f3f88 to your computer and use it in GitHub Desktop.

Select an option

Save betorobson/23e5914b51e844bac5eaa6032d6f3f88 to your computer and use it in GitHub Desktop.

Revisions

  1. betorobson revised this gist Oct 18, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,15 @@
    ```bash
    $ mkdir hooks && curl -o hooks/post-merge -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-merge && curl -o hooks/post-checkout -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-checkout
    ```
    ###2. Add a script install at your package.json
    ### 2. Add a script install at your package.json
    ```json
    ...
    "scripts": {
    "install": "cp ./hooks/* .git/hooks/ && chmod -R a+X .git/hooks/"
    },
    ...
    ```
    ###3. Commit and push to remote repository
    ### 3. Commit and push to remote repository
    #### At this point your team will get any change on package.json and bower.json files

    #### Thanks to these two guys:
  2. betorobson revised this gist Oct 18, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Git hooks for NPM and Bower Projects

    ##1. Copy theses files into your hooks folder
    ## 1. Copy theses files into your hooks folder
    ```bash
    $ mkdir hooks && curl -o hooks/post-merge -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-merge && curl -o hooks/post-checkout -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-checkout
    ```
  3. betorobson revised this gist Oct 18, 2017. 2 changed files with 5 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -9,3 +9,5 @@ check_run() {

    check_run package.json "npm prune && npm install"
    check_run bower.json "bower prune && bower install"

    exit 0;
    4 changes: 3 additions & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -9,4 +9,6 @@ check_run() {
    }

    check_run package.json "npm prune && npm install"
    check_run bower.json "bower prune && bower install"
    check_run bower.json "bower prune && bower install"

    exit 0;
  4. betorobson revised this gist Feb 21, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,8 @@ $ mkdir hooks && curl -o hooks/post-merge -O https://gist.github.com/
    },
    ...
    ```

    ### At this point your team will get any change on package.json and bower.json files
    ###3. Commit and push to remote repository
    #### At this point your team will get any change on package.json and bower.json files

    #### Thanks to these two guys:
    - https://gist.github.com/sindresorhus/7996717
  5. betorobson revised this gist Feb 21, 2017. 1 changed file with 3 additions and 7 deletions.
    10 changes: 3 additions & 7 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,10 @@
    # Git hooks for NPM and Bower Projects

    ##1. Create a hooks folder
    ##1. Copy theses files into your hooks folder
    ```bash
    $ mkdir hooks
    $ mkdir hooks && curl -o hooks/post-merge -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-merge && curl -o hooks/post-checkout -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-checkout
    ```
    ##2. Copy theses files into your hooks folder
    ```bash
    $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-merge && chmod +x post-merge && mv post-merge hooks/ && curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-checkout && chmod +x post-checkout && mv post-checkout hooks/
    ```
    ###3. Add a script install at your package.json
    ###2. Add a script install at your package.json
    ```json
    ...
    "scripts": {
  6. betorobson revised this gist Feb 20, 2017. No changes.
  7. betorobson revised this gist Feb 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ $ mkdir hooks
    ```
    ##2. Copy theses files into your hooks folder
    ```bash
    $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/post-merge && chmod +x post-merge && mv post-merge hooks/ && curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/post-checkout && chmod +x post-checkout && mv post-checkout hooks/
    $ curl -O https://gist.githubusercontent.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-merge && chmod +x post-merge && mv post-merge hooks/ && curl -O https://gist.githubusercontent.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/raw/e02ee803af1094a0dbff6c47febe02e1f5cb33b8/post-checkout && chmod +x post-checkout && mv post-checkout hooks/
    ```
    ###3. Add a script install at your package.json
    ```json
  8. betorobson revised this gist Feb 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po
    ...
    ```

    ### At this point your team will get any change at package.json and bower.json files
    ### At this point your team will get any change on package.json and bower.json files

    #### Thanks to these two guys:
    - https://gist.github.com/sindresorhus/7996717
  9. betorobson revised this gist Feb 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po
    ...
    ```

    ### At this point your team will get any changes at package.json and bower.json files
    ### At this point your team will get any change at package.json and bower.json files

    #### Thanks to these two guys:
    - https://gist.github.com/sindresorhus/7996717
  10. betorobson revised this gist Feb 20, 2017. No changes.
  11. betorobson revised this gist Feb 20, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po
    ### At this point your team will get any changes at package.json and bower.json files

    #### Thanks to these two guys:
    https://gist.github.com/sindresorhus/7996717
    https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f
    - https://gist.github.com/sindresorhus/7996717
    - https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f
  12. betorobson revised this gist Feb 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,6 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po

    ### At this point your team will get any changes at package.json and bower.json files

    Thanks to these two guys:
    #### Thanks to these two guys:
    https://gist.github.com/sindresorhus/7996717
    https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f
  13. betorobson revised this gist Feb 20, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po
    ### At this point your team will get any changes at package.json and bower.json files

    Thanks to these two guys:
    (https://gist.github.com/sindresorhus/7996717)
    (https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f)
    https://gist.github.com/sindresorhus/7996717
    https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f
  14. betorobson revised this gist Feb 20, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,8 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po
    ...
    ```

    ### At this point your team will get any changes at package.json and bower.json files
    ### At this point your team will get any changes at package.json and bower.json files

    Thanks to these two guys:
    (https://gist.github.com/sindresorhus/7996717)
    (https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f)
  15. betorobson revised this gist Feb 20, 2017. 3 changed files with 8 additions and 12 deletions.
    5 changes: 3 additions & 2 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,11 @@
    #!/usr/bin/env bash
    # fork from https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f

    changed_files="$(git diff-tree -r --name-only --no-commit-id $1 $2)"

    check_run() {
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
    }

    check_run package.json "npm prune && npm install"
    check_run bower.json "bower prune && bower install"
    check_run bower.json "bower prune && bower install"
    11 changes: 2 additions & 9 deletions post-merge
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,12 @@
    #!/usr/bin/env bash
    # MIT © Sindre Sorhus - sindresorhus.com

    # git hook to run a command after `git pull` if a specified file was changed
    # Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
    # fork from https://gist.github.com/sindresorhus/7996717

    changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"

    check_run() {
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
    }

    # Example usage

    # In this example it's used to run `npm install` if package.json changed
    check_run package.json "npm prune && npm install"

    # In this example it's used to run `bower install` if bower.json changed
    check_run bower.json "bower prune && bower install"
    check_run bower.json "bower prune && bower install"
    4 changes: 3 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,6 @@ $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/po
    "install": "cp ./hooks/* .git/hooks/ && chmod -R a+X .git/hooks/"
    },
    ...
    ```
    ```

    ### At this point your team will get any changes at package.json and bower.json files
  16. betorobson revised this gist Feb 20, 2017. 1 changed file with 6 additions and 32 deletions.
    38 changes: 6 additions & 32 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,10 @@
    #!/bin/bash
    # Does not run if your local branch is behind the remote.
    # https://gist.github.com/stefansundin/82051ad2c8565999b914
    #!/usr/bin/env bash

    # Exit early if this was only a file checkout, not a branch change ($3 == 1)
    [[ $3 == 0 ]] && exit 0
    changed_files="$(git diff-tree -r --name-only --no-commit-id $1 $2)"

    oldRef=$1
    newRef=$2

    # Exit early if the local branch is behind the remote
    LOCAL=$(git rev-parse @)
    REMOTE=$(git rev-parse @{u} 2> /dev/null)
    BASE=$(git merge-base @ @{u} 2> /dev/null)

    if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then
    echo "You are behind origin, not running bundle/migrate post-checkout hook."
    exit 1
    fi


    function changed {
    git diff --name-only $oldRef $newRef | grep "^$1" > /dev/null 2>&1
    check_run() {
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
    }

    if changed 'bower.json'; then
    echo "bower.json changed, installing"
    bower prune
    bower install
    fi

    if changed 'package.json'; then
    echo "Package.json changed, installing"
    npm prune
    npm install
    fi
    check_run package.json "npm prune && npm install"
    check_run bower.json "bower prune && bower install"
  17. betorobson revised this gist Feb 20, 2017. 2 changed files with 41 additions and 1 deletion.
    36 changes: 36 additions & 0 deletions post-checkout
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/bin/bash
    # Does not run if your local branch is behind the remote.
    # https://gist.github.com/stefansundin/82051ad2c8565999b914

    # Exit early if this was only a file checkout, not a branch change ($3 == 1)
    [[ $3 == 0 ]] && exit 0

    oldRef=$1
    newRef=$2

    # Exit early if the local branch is behind the remote
    LOCAL=$(git rev-parse @)
    REMOTE=$(git rev-parse @{u} 2> /dev/null)
    BASE=$(git merge-base @ @{u} 2> /dev/null)

    if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then
    echo "You are behind origin, not running bundle/migrate post-checkout hook."
    exit 1
    fi


    function changed {
    git diff --name-only $oldRef $newRef | grep "^$1" > /dev/null 2>&1
    }

    if changed 'bower.json'; then
    echo "bower.json changed, installing"
    bower prune
    bower install
    fi

    if changed 'package.json'; then
    echo "Package.json changed, installing"
    npm prune
    npm install
    fi
    6 changes: 5 additions & 1 deletion post-merge
    Original file line number Diff line number Diff line change
    @@ -11,5 +11,9 @@ check_run() {
    }

    # Example usage

    # In this example it's used to run `npm install` if package.json changed
    check_run package.json "npm install"
    check_run package.json "npm prune && npm install"

    # In this example it's used to run `bower install` if bower.json changed
    check_run bower.json "bower prune && bower install"
  18. betorobson revised this gist Feb 20, 2017. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,16 @@
    ##1. Create a hooks folder
    ```bash
    $ mkdir hooks
    ```
    ##2. Copy theses files into your hooks folder
    ```bash
    $ curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/post-merge && chmod +x post-merge && mv post-merge hooks/ && curl -O https://gist.github.com/betorobson/23e5914b51e844bac5eaa6032d6f3f88/post-checkout && chmod +x post-checkout && mv post-checkout hooks/
    ```
    ###3. Add a script install at your package.json
    ```json
    ...
    "scripts": {
    "install": "cp ./hooks/* .git/hooks/ && chmod -R a+X .git/hooks/"
    },
    ...
    ```
  19. betorobson revised this gist Feb 20, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,6 @@
    # Git hooks for NPM and Bower Projects

    ##1. Create a hooks folder
    ```bash
    $ mkdir hooks
    ```
  20. betorobson revised this gist Feb 20, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Git hooks for NPM and Bower Projects
  21. betorobson renamed this gist Feb 20, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  22. betorobson renamed this gist Feb 20, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  23. @sindresorhus sindresorhus revised this gist Jul 16, 2016. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions post-merge
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #/usr/bin/env bash
    #!/usr/bin/env bash
    # MIT © Sindre Sorhus - sindresorhus.com

    # git hook to run a command after `git pull` if a specified file was changed
    @@ -11,6 +11,5 @@ check_run() {
    }

    # Example usage
    # In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.
    # In this example it's used to run `npm install` if package.json changed
    check_run package.json "npm install"
    check_run bower.json "bower install"
  24. @sindresorhus sindresorhus created this gist Dec 16, 2013.
    16 changes: 16 additions & 0 deletions post-merge
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #/usr/bin/env bash
    # MIT © Sindre Sorhus - sindresorhus.com

    # git hook to run a command after `git pull` if a specified file was changed
    # Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.

    changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"

    check_run() {
    echo "$changed_files" | grep --quiet "$1" && eval "$2"
    }

    # Example usage
    # In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.
    check_run package.json "npm install"
    check_run bower.json "bower install"