[Development] clang-format

Frederik Gladhorn Frederik.Gladhorn at qt.io
Mon Oct 14 13:45:59 CEST 2019


Hi,

after just a bit over a year, we have a hint of progress on the state of using 
clang-format.

If you use qt5.git, you'll get the git hook for it set up, to automatically 
run clang-format on the lines you changed.
To benefit today, get the dev branch of qt5 and run init-repository -f --force-
hooks.
The commit hook runs and shows a diff of what should be changed, but doesn't 
add anything, so your changes should be safe from unwanted reformatting no 
matter what.
If you think the changes make sense, just run "git clang-format" and all the 
things you have added to the staging area will be reformatted.

git add myfile # stage a file
git commit # try to commit, clang-format thinks you need to reformat
git clang-format # apply the reformatting to the index
git diff # see what clang-format did

The hook script which is probably far from optimal (written in sh) is found in 
qt/qtrepotools. You can also just link https://code.qt.io/cgit/qt/
qtrepotools.git/tree/git-hooks/clang-format-pre-commit as pre-commit into your 
.git/hooks directory and you get to enjoy it.

I bet we'll have some issues and it's not quite perfect, but hey, small 
progress.

Enjoy re-formatting and feel relaxed about it too ;)

Cheers,
Frederik





More information about the Development mailing list