Giter Club home page Giter Club logo

git-confirm's Introduction

git-confirm Travis Build Status

Git hook to catch placeholders and temporary changes (TODO / @ignore) before you commit them.

Asciicast DEMO

Git Confirm:

  • Stops you ever accidentally committing bad temporary changes.
  • Is interactive, checking each match with you so you can't miss it (and can still include it if you like).
  • Only considers lines newly added and about to be committed, so no false positives.
  • Includes (diff-colorized) context with each match
  • Installs in any project with a single command
  • Is configurable to match any number of strings, through standard git config
  • Is well tested. See tests/test-hook.bats.
  • Works on Linux, OSX and Windows (in Powershell at least), with no dependencies.

To Install

In the root of your Git repository, run:

curl -sSfL https://cdn.rawgit.com/pimterry/git-confirm/v0.2.2/hook.sh > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

(Note the version number)

All done. If you want to check it's installed correctly you can run:

echo "TODO" > ./test-git-confirm
git add ./test-git-confirm

# Should prompt you to confirm added 'TODO'. Press 'n' to cancel commit.
git commit -m "Testing git confirm"

If you're security conscious, you may be reasonably suspicious of curling executable files. Here you're on HTTPS throughout though, and you're not piping directly to execution so you can check contents and the hash (against MD5 9ee7ff55f7688f9055a9056bd2617a02 for v0.2.2) before using this, if you like.

To Configure

By default, git-confirm will catch and warn about lines including 'TODO' only.

If you want to match a different pattern, you can override this default and set your own patterns:

git config --add hooks.confirm.match "TODO"

Matches are passed verbatim to your local grep, and are treated as regular expressions. Note that all matches are case-sensitive.

You can repeatedly add patterns, and each of them will be matched in turn. To get, remove or totally clear your config, use the standard Git Config commands:

git config --get-all hooks.confirm.match
git config --unset hooks.confirm.match 'TODO'
git config --unset-all hooks.confirm.match

Contributing

Want to file a bug? That's great! Please search issues first though to check it hasn't already been filed, and provide as much information as you can (your OS, terminal and Git-Confirm version as a minimum).

Want to help improve Git-Confirm?

  • Check out the project: git clone --recursive https://github.com/pimterry/git-confirm.git

    (Note 'recursive' - this ensures submodules are included)

  • Check the tests pass locally: ./test.sh

  • Add tests for your change in test/test-hook.bats

    Check out the BATS documentation if you're not familiar with it, or just crib from the existing tests.

  • Add any documentation required to this README.

  • Commit and push your changes

  • Open a PR!

Need any ideas? Take a look at the Git Confirm Huboard to quickly see the next features to look at.

Release process

  • Make changes
  • Update Curl version number and hash (md5 ./hook.sh) in README.
  • Commit everything
  • Tag with new version numbers (git tag vX.Y.Z)
  • Push including tags (git push origin --tags)

git-confirm's People

Contributors

dahbearz avatar periodic avatar pimterry avatar trissylegs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-confirm's Issues

Allow ignoring files from confirmation

Minified compiled output often includes lots of existing matches, and appears to have been entirely changed when any build happens, so requires confirmation every time.

Instead, it'd be nice to be able to ignore build output folders for confirmation, and require confirmation only from source changes.

Allow including 'all' in a file (like git add -p)

Currently you can only y/n each confirmation. If you've got a really big file though, which repeatedly matches, you might have to confirm quite a few times. If you have committed generated code in a repo, it's very easy to get false positives from this, and it'd be useful to have 'a' (for 'all') as an option, which confirms everything in the current file.

Skip the check for WIP commits

If a commit message subject starts with WIP (also seen as [WIP] and lowercase), allowing otherwise blocked content without a prompt would be useful.

Handle custom git diff colours

Current implementation assumes green non-bold text is added lines. This is configurable (as git config color.diff.new). Would be good to check if it has been reconfigured and match differently configured colors instead.

Colour highlighting for the match itself

Currently grep outputs the line by line matches. Weirdly, grep itself is happy to output in colour (visible if run directly on my machine) but the colour disappears if it's run inside the git hook. Maybe git blocks it? Maybe grep tries to detect colour support, and can't find it?

Handle first commit case

When run on the very first commit in a repository Git Confirm currently throws:

fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Doesn't play well with vim-fugitive.

This causes some weird buggy behaviour when combined with fugitive.
I'm not sure if this is an issue with the way git-confirm works or with fugitive.
I'll investigate further when I have a bit more time.

Non-standard color support

Users can set colors themselves, so assuming green is not really robust (e.g., red/green colorblind users might have a non-green addition color set). It might just be better to not use color and instead use something like colordiff to color the diff afterwards.

Add explicit NPM support

Should be able to add a package.json so this can be published as an NPM package, depend on GHooks, and automatically add the relevant ghook config to NPM config when we're installed.

Need to fail loudly if there's already a pre-commit hook, since we should pass over to manual merging.

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.