Giter Club home page Giter Club logo

git-hooks-core's Introduction

git-hooks-core

An opinionated use of the core.hooksPath feature released in Git 2.9.

ABOUT

This repository is meant to be used as the directory that the Git core.hooksPath config value is pointed at.

It exists because using the core.hooksPath feature is used in place of any local, repository-specific hooks in .git/hooks. This isn't necessarily what you want, as you may have repository-specific hooks that you want to run in addition to some hooks that should be global.

If you use this repository as your core.hooksPath, you will be able to:

  • Retain any repository-specific hooks in .git/hooks
  • Add hooks that will apply to all repositories in their respective .d folder
  • Use multiple files for hooks rather than a single file, as Git expects
  • Whitelist specific repositories against specific hooks (See Whitelists)

And now that the hooks dir is outside of your repository, you can commit the global hooks. Hooray!

INSTALLATION

Clone this repo to your directory of choice, e.g. $HOME/workspace/git-hooks-core.

git clone https://github.com/pivotal-cf/git-hooks-core $HOME/workspace/git-hooks-core

This repo comes with some hooks by default that depend on cred-alert-cli. You can download this from the links below.

CUSTOMIZATION

If you're a Pivotal team and you would like your own collection of hooks then please add a branch to this repository with the name team/<team-name>. For example, if I was on a security team I would push a branch to team/pcf-security. We originally wanted to have people fork this repository but that requires administrator access for the destination organization.

If you use sprout-git to install this then you can use the sprout.git.hooks.revision attribute to set the branch you would like to use.

CRED-ALERT

To install the cred-alert-cli binary download the version for your OS (macOs or Linux), rename it to cred-alert-cli, make it executable, and move it to a directory in ${PATH}.

os_name=$(uname | awk '{print tolower($1)}')
curl -o cred-alert-cli \
  https://s3.amazonaws.com/cred-alert/cli/current-release/cred-alert-cli_${os_name}
chmod 755 cred-alert-cli
mv cred-alert-cli /usr/local/bin # <= or other directory in ${PATH}

USAGE

Point core.hooksPath at the directory you cloned this repo to:

git config --global --add core.hooksPath $HOME/workspace/git-hooks-core

Add any global hooks you'd like to their respective .d folder:

chmod +x my-commit-msg-hook
cp my-commit-msg-hook $HOME/workspace/git-hooks-core/commit-msg.d

Whitelists

This repository supports whitelisting repositories against specific files in the hook_name.d folders.

.
├── whitelists      # contains a mapping of hooks to whitelists
└── whitelists.d    # contains whitelists
    └── cred-alert  # a whitelist

The whitelists file within git-hooks-core is used to declare which hooks are affected by the whitelists that live in whitelists.d/. The structure is as follows:

$HOOK_PATH $WHITELIST

Where HOOK_PATH is a relative path pointing to a file in a hook_name.d folder in the git-hooks-core directory and WHITELIST is the name of the file that resides in git-hooks-core/whitelists.d/.

Each whitelist file should contain absolute paths to the repositories that the whitelist affects. For example, if you had a repository /home/username/my-repo that you wanted to whitelist against a commit-msg hook called add_footer, you would:

  1. Create a file, git-hooks-core/whitelists.d/my-whitelist with a single entry: /home/username/my-repo
  2. Add an entry to git-hooks-core/whitelists: commit-msg.d/add_footer my-whitelist

git-hooks-core/whitelists has been preconfigured with entries for the (initially empty) cred-alert whitelist in whitelists.d.

LINKS

CLI Binaries:

git-hooks-core's People

Contributors

krishicks avatar xoebus avatar jfmyers9 avatar jvshahid avatar madamkiwi avatar leesaferite avatar robdimsdale avatar aramprice avatar

Watchers

Mark Alston avatar James Cloos avatar

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.