Giter Site home page Giter Site logo

git-cpp-check's Introduction

git-cpp-check

Combines git-clang-format (found e.g. in LLVM package) and cpplint to check your code before commit.

Usage

  1. Get:
  2. Add clang-format tool to your system path or tell git where it is: $ git config clangformat.binary path/to/clang-format[.exe]
  3. Make git-cpp-check executable.
  4. Add git-cpp-check to your pre-commit script. If git-clang-format or cpplint.py aren't in the same directory as git-cpp-check, you need to tell git-cpp-check where they are. Edit .git/hooks/pre-commit: /path/to/git-cpp-check --cpplint="/path/to/cpplint.py" --git-clang-format="/path/to/git-clang-format" The paths can be relative to the git root directory.

How does it work?

Git-cpp-check works on files added to you git commit. Cpplint reads the whole file but only lines changed by commit are taken into account. This means that if there are e.g. Cpplint errors in other parts of your code untouched by commit, no error will be reported [1].

Working with git-cpp-check

When working with git-cpp-check, you want to stage (git add) all your changes before attempting to commit them. The script will refuse to modify any file with unstaged changes.

Once you've staged all your changes, commit them like usually - the pre-commit hook will be executed. This can lead to:

  1. The commit proceeds as usual, which means your changes were simply accepted.
  2. The script reported cpplint issues, listing them for you. The commit is automatically aborted. You need to fix the issues, stage them (git add) and try to commit again.
  3. The script modified some files with clang-format. The changes are listed for you in the diff format. At this point the command git add -p can be recommended. Git will ask you about each change whether you want to stage it or not. Usually you'll accept all the changes, but sometimes you can manually format your code better than clang-format or you just don't want to reformat a large multi-line expression just because you changed one word. If you want to reject any change, just don't stage it - answer "n" and leave it unstaged. Then just try to commit again. The script won't complain about the unstaged changes, because it won't have any additional changes to apply, and only the staged changes will be committed. After the commit succeeds, you can get rid of the unstaged clang-format changes by running git reset --hard.

Notes

If you don't want the script to be run, add -n option to the commit command.

Limitations

Current version of git-cpp-check doesn't allow you to fine tune your linter and formatter as you could using these tools separately. Clang format uses Chromium style.


[1] This could be improved by displaying a warning.

git-cpp-check's People

Contributors

bwiklak avatar kristoczaj avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kristoczaj solrex

git-cpp-check's Issues

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.