add clang-format to right click menus for files
Very frequent operation: clang formatting a file or commit set. Very often using "launch editor" to get this.
This could be achieved simply by running on each file that is right clicked individually. It would be helpful if one could run clang-format over the entire commit-set too, perhaps guard this one with a confirmation dialog. Never overwrite the staged data, leave altering the staged data to the committer so the autoformat changes can be reviewed ( this equates to don't do anything fancy ).
The clang format command / path should be a preference, often there is a special path to clang-format, and with concurrent versions, sometimes it's clang-format-8, -9, -10 etc.
A bonus feature, though a follow on effort as I would like the core functionality first, would be to run clang-format as a dry run for every staged file and determine if the file needs formatting, and visually indicating that through maybe color of the icon, say orange/yellow/purple. Opt out would be good to allow here, under the gear actions preferences. This is just an indicator, I suppose you can make it block the commit button and allow opt-in/out via gear/actions as well (default on?).
I like the idea. It'd be cool to extend this similar to the guitool feature, where users can add extension commands that show up in the "Actions" menu.
https://git-cola.readthedocs.io/en/latest/git-cola.html#custom-gui-actions
You can approximate this feature today by adding the snippet below to your ~/.gitconfig and it'll show up in the Actions menu. A cool extension would be for commands that can operate on multiple files, and for them to be accessible from the right-click menu. Hotkey assignment is supported currently so you could assign this to something and you wouldn't need the menu action.
[guitool "clang-format"]
cmd = clang-format -i $FILENAME
needsfile = true
background = true
Maybe something simple like diff_menu = true would make it show up in the diff context menu. For handling multiple files, it might make sense to use the natural "$@" shell syntax.
A proposal for this issue is to support this configuration:
[guitool "clang-format"]
cmd = clang-format -i "$@"
needsfile = true
background = true
diff_menu = true
The preferences screen can provide some bult-ins that we can ship and make easy to enable, for example the snippet above. At that point it would make sense to have a simple editor for custom commands, rather than it being a hidden feature, but that can come later.
@nevion Use a git pre-commit hook to accomplish this, and more. pre-commit is a very widely-used tool that can install and run pre-commit hooks for you, and there are several pre-commit hook implementations of clang-format already available.
@davvid I think this issue can be closed.
Thanks @kurtmckee I agree. The diff_menu and "$@" features are nice enhancements, but since we already have support for guitool.* then there's not really a big need for those just yet.
I added a label so we can find it in the future in case we end up wanting to add those enhancements.