elvout / cs393r

CS 393R Graduate Autonomous Robots, Fall 2021 | Autobots
0 stars 0 forks source link

Format staged C++ files in pre-commit hook #4

Closed elvout closed 3 years ago

elvout commented 3 years ago

I've created a Git hook to automatically format staged C++ files before a commit.

It formats entire files but only re-stages sections of the C++ files that were already staged for commit. This preserves the functionality of git add --patch.

It turns out that this task is not trivial, but I think I've documented it fairly well. There's probably a more efficient way to do this (it currently has to do 2 passes), but I think at this point I should be investing more time into the assignment itself lol.

The pre-commit hook needs to be symlinked from.githooks into the .git/hooks directory.

aiddun commented 3 years ago

Looks good, appreciate the comments.