{"id":16546928,"url":"https://github.com/barisione/clang-format-hooks","last_synced_at":"2025-04-06T14:10:21.036Z","repository":{"id":56662076,"uuid":"135837237","full_name":"barisione/clang-format-hooks","owner":"barisione","description":"Apply a coding style with clang-format only to new code added to an existing code base.","archived":false,"fork":false,"pushed_at":"2025-03-11T08:54:50.000Z","size":271,"stargazers_count":207,"open_issues_count":13,"forks_count":57,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T13:07:38.237Z","etag":null,"topics":["c","clang","clang-format","cpp","git","gitbook","objective-c","syntax"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/barisione.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-02T17:13:55.000Z","updated_at":"2025-03-25T09:34:55.000Z","dependencies_parsed_at":"2024-10-27T11:11:07.775Z","dependency_job_id":"75492484-ca72-4a85-beb5-f0b95ebf66ed","html_url":"https://github.com/barisione/clang-format-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisione%2Fclang-format-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisione%2Fclang-format-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisione%2Fclang-format-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barisione%2Fclang-format-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barisione","download_url":"https://codeload.github.com/barisione/clang-format-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492513,"owners_count":20947544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","clang","clang-format","cpp","git","gitbook","objective-c","syntax"],"created_at":"2024-10-11T19:13:03.441Z","updated_at":"2025-04-06T14:10:21.011Z","avatar_url":"https://github.com/barisione.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build status](https://api.travis-ci.org/barisione/clang-format-hooks.svg?master)](https://travis-ci.org/barisione/clang-format-hooks)\n\n`clang-format` git hooks\n========================\n\n***Apply a coding style with `clang-format` only to new code added to an existing code base.***\n\nAt [Undo](https://www.undo.io/), we decided to use the `clang-format` tool to enforce a consistent coding style for new and refactored code, but without changing the existing one.\n\nThis is done through a script (`apply-format`) which can be run manually or through a pre-commit `git` hook which is run every time just before code is committed.\n\n\u003cimg src=\"docs/screenshot-hook.png\" width=\"595\" height=\"420\"\u003e\u003c/img\u003e\n\n### What is `clang-format`?\n\n`clang-format` is a tool, part of the LLVM project, which can reformat code to adhere to a configured style.\n\nBy default, `clang-format` supports a few pre-defined styles matching the style used by a few important projects, but it's possible to customise specific styles.\n\n\nSetup\n-----\n\n### Dependencies\n\n*  **Ubuntu and Debian:** install the `clang-format` package. You can install a newer version with [these instructions](docs/NewerClangFormatUbuntu.md).\n*  **Fedora, CentOS and Red Hat:**  install the `clang` package.\n*  **macOS:** install `clang-format` using HomeBrew: `brew install clang-format`.\n\nYou can optionally install `colordiff` to get nicer output.\n\n### Configuring `clang-format`\n\n`clang-format` needs to be configured to reformat code according to your project's preferred style.\u003cbr\u003e\nAll the options are described in the official [style options documentation](https://clang.llvm.org/docs/ClangFormatStyleOptions.html), but a great way to start is to use an [interactive configurator](https://zed0.co.uk/clang-format-configurator/).\n\nOnce you found the correct style options, just save them in a file called `.clang-format` in the top level directory of your project. From here, the scripts, will load the style automatically.\n\n### Scripts\n\nAdd the `apply-format` and `git-pre-commit-format` scripts to your repositories.\n\nYou can either copy them (maybe in a `scripts/` sub-directory) or add this whole repository as a `git` submodule.\n\n### Registering the `git` hook\n\nRun at a terminal:\n\n```sh\n$ ./git-pre-commit-format install\n```\n\nThis will add a hook (in `.git/hooks/`) which is run every time you commit.\n\n\nUsing the pre-commit hook\n-------------------------\n\nAfter registering the git hook, you don't need to do anything except for committing your changes.\n\nEvery time you commit, the hook will check if your code matches the coding standard. If it doesn't, you get asked what to do and you can decide to:\n\n* Apply the fixes automatically (only to the code you are actually committing, not to unstaged code).\n* Commit anyway.\n* Abort the commit so you can fix the problem manually.\n\nNote that, if you use `git` through a GUI or some other tool (i.e. not directly on the command line), the script will fail to get your input.\nIn this case disable the interactive behaviour with:\n\n```sh\n$ git config hooks.clangFormatDiffInteractive false\n```\n\nFor more information on the script use the ``--help`` option.\n\n\nManual script\n-------------\n\nYou can also reformat changed code without committing it using the `apply-format` script directly.\n\nBy default, ``apply-format`` reformats only the code which was modified, i.e.  the code that ``git diff`` would show, and prints the diff to the terminal.\n\nIf you want to automatically apply the suggested changes, run the script with ``-i``.\n\nIf you only want to reformat your staged changes, but not the unstanged ones, use ``--staged``.\n\nFor instance, a possible workflow would be similar to:\n\n```sh\n$ # Make some changes.\n$ vi foo.c\n$ # Stage changes you want to commit.\n$ git add -p\n$ # Reformat the staged changes you made.\n$ ./scripts/apply-format -i --staged\n$ # Commit the result.\n$ git commit\n```\n\nIt’s also possible to reformat a whole file (using ``--whole-file`` or its\nshorter form ``-f``).\n\nFor more information on the script use the ``--help`` option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarisione%2Fclang-format-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarisione%2Fclang-format-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarisione%2Fclang-format-hooks/lists"}