Skip to content
This repository has been archived by the owner on Feb 21, 2021. It is now read-only.

Fix #34: Add git pre-commit hook script for running Cpplint #41

Closed

Conversation

hustcalm
Copy link
Collaborator

Hi there,

I just got a working git pre-commit hook for running Cpplint before each commit, it should be very easy to get used to it. I will give a simple walkthrough here, currently it's very basic and hopefully we can do some enhancements together.

The install should be very easy, just go to the JdeRobot root directory and run:

./scripts/git/install-pre-commmit.sh

The typical process would be like:

  • Develop a feature or fix a bug, etc
  • Add the changes
  • Try to do a commit
  • Cpplint runs once the pre-commit hook triggers
  • According to the lint outputs, conform commit or abort to further modifications

OK, let's go with some really easy C++ source code. We got a testCppLint.cpp and have:

#include <iostream>
 using namespace std;

 int main()
 {
     cout<<"Hello CppLint!"<<endl;
     return 0;
 }

Another file testCppLint-1.cpp and have:

#include <iostream>

 int main()
 {
     std::cout<<"Hello CppLint!"<<std::endl;
     return 0;
 }

Add the files

git-add-files

Git commit

git-pre-commit-hook-cpplint

If answer y, then the commit will be conformed, otherwise a n will abort the commit.

Git commit with --no-verity

git-commit-no-verify

You can always pass --no-verify to commit to bypass the pre-commit hook.

@hustcalm
Copy link
Collaborator Author

hustcalm commented Apr 2, 2015

@GitHubBrowser
Thanks for your comments, currently this is the very basic infrastructure for the pre-commit hooks.

Well, I haven't tested the hook using a GUI, there may be incompatible because the scripts are designed for Terminal. Hopefully if you are more comfortable with the GUI, you can come up with a hook working and create a pull request here.

Thanks for the Nitpick, my bad. It should be, however as we have not settled down completely about the programming style(see #22 ), so it would currently work like this. People are free to use --no-verify to bypass anyway.

Like I said, the hook is a very beginning now. Welcome for more discussion and contribution!

@hustcalm
Copy link
Collaborator Author

hustcalm commented Apr 2, 2015

@GitHubBrowser
I just realized that you are the maintainer of Pre-commit-hooks.

For the missing input, do you mean the below lines?

#Allows us to read user input below, assigns stdin to keyboard, use 'exec <&-' to close it
+exec < /dev/tty

As the comments say, +exec < /dev/tty will open stdin of keyboard and exec <&- will close it.

However for working with GUI, I have no idea currently. Hopefully we can figure something out together:-)

@ddddavidmartin
Copy link

@hustcalm I was going to have a look and see what it looks like for example when using Github for Mac but it turns out my MacOS version is too old. Might try one of the other programs. But yes, I'm fine with the terminal too.

@hustcalm
Copy link
Collaborator Author

@GitHubBrowser OK, hopefully I will give it a shot too on my Mac running 10.10 Yosemite. If anything to help, please let me know.

@varhub varhub added the delayed label Dec 15, 2015
@fqez
Copy link
Member

fqez commented Jul 27, 2017

This will be revisited soon. Meanwhile, I close this PR.

@fqez fqez closed this Jul 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants