{"id":16139564,"url":"https://github.com/bergercookie/clang_git_format","last_synced_at":"2025-04-06T17:43:35.771Z","repository":{"id":78140152,"uuid":"94533951","full_name":"bergercookie/clang_git_format","owner":"bergercookie","description":"clang_git_format - Python wrapper for bulk reformatting of Git repos","archived":false,"fork":false,"pushed_at":"2017-07-04T13:16:09.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T23:45:59.454Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bergercookie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2017-06-16T10:33:47.000Z","updated_at":"2017-06-16T10:35:59.000Z","dependencies_parsed_at":"2023-02-28T15:45:11.193Z","dependency_job_id":null,"html_url":"https://github.com/bergercookie/clang_git_format","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/bergercookie%2Fclang_git_format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergercookie%2Fclang_git_format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergercookie%2Fclang_git_format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergercookie%2Fclang_git_format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bergercookie","download_url":"https://codeload.github.com/bergercookie/clang_git_format/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526675,"owners_count":20953141,"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":[],"created_at":"2024-10-09T23:49:20.511Z","updated_at":"2025-04-06T17:43:35.748Z","avatar_url":"https://github.com/bergercookie.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clang_git_format - Python wrapper for bulk reformatting of Git repos\n\n## General Information\n\nCurrent repository offers an automated solution to the reformatting of entire\nprojects managed by Git. It was inspired by [the series of\narticles](https://engineering.mongodb.com/post/succeeding-with-clangformat-part-1-pitfalls-and-planning/)\nof how MongoDB used clang-format to reformat their codebase. As a backbone for\nthis package, the MongoDB\n[clang_format.py](https://github.com/mongodb/mongo/blob/master/buildscripts/clang_format.py)\nhas been used. Most notably package has the following capabilities:\n\n- Make sure a predetermined (`see clang_git_format/config.py` ) version of\n    clang-format script is to be used. If one is not installed, the\n    `ClangFormat` object is responsible of downloading and setting one up.\n- Run clang-format using the `~/.clang-format` configuration file. A sample\n    file is provided along with the python code. Symlink it to your home\n    directory if you want to use it.\n\n- Format a code Git repo. User can optionally provide the programming\n    language(s) that the repository holds so that clang-format runs on the files\n    of that language only. By default C++ is assumed.  Run\n    `clang_git_format --help for a list of provided languages`.\n\n- In case of unmerged code in a user (stray) branch users can also use the\n    `clang_git_format --reformat_branch \u003cstart_commit\u003e \u003cend_commit\u003e`to sync his\n    code with the formatting changes of the master branch. For more information\n    on how this is done, read [this\n    article](https://engineering.mongodb.com/post/succeeding-with-clangformat-part-3-persisting-the-change).\n\n- Validate that a specific set of files complies to the clang-format rules that\n    is set. This can be handy in cases when one wants to integrate clang-format\n    into a continuous integration (CI) system to verify that all incoming\n    pull-requests / commits comply to the repo's coding style.\n\nThis package differs to the initial MongoDB script in the following points:\n\n- It's refactored into a sane python package and breaks definition of classes,\n    utility methods into separate python files for readability.\n\n- Uses the powerful\n    [argparse](https://docs.python.org/dev/library/argparse.html) module instead\n    of the deprecated optparse.\n\n- It's more generic (doesn't depend on the MongoDB repo configuration), can be\n    used with an arbitrary Git repository and is not tied to the repo language\n    (C++, Javascript).\n\n\n## Usage Instructions\n\nA typical usage of the script would be the following\n\nA list of command-line options is the following. Run `--help` yourself for an\nup-to-date list of options:\n\n\n```\n\n$ ./format_code.py --help\n\nusage: format_code.py [-h] [-c CLANG_FORMAT] -g GIT_REPO [-a LANG [LANG ...]]\n                      [-x REGEX] [-i DIRS_IN [DIRS_IN ...]]\n                      [-o DIRS_OUT [DIRS_OUT ...]]\n                      (-l | -L | -p LINT_PATCHES [LINT_PATCHES ...] | -b REFORMAT_BRANCH REFORMAT_BRANCH | -f | -F)\n\nApply clang-format to a whole Git repository. Execute this script and provide\nit with the path to the git repository to operate in. WARNING: You have to run\nit from the root of the repo if you want to apply its actions to all the\nfiles.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c CLANG_FORMAT, --clang_format CLANG_FORMAT\n                        Path to the clang-format command.\n  -g GIT_REPO, --git_repo GIT_REPO\n                        Relative path to the root of the git repo that is to\n                        be formatted/linted.\n  -a LANG [LANG ...], --lang LANG [LANG ...]\n                        Languages used in the repository. This is used to\n                        determinethe files which clang format runs for.\n                        Default langs: {'const': None, 'help': 'Languages used\n                        in the repository. This is used to determinethe files\n                        which clang format runs for. Default langs: %s.',\n                        'option_strings': ['-a', '--lang'], 'dest': 'lang',\n                        'required': False, 'nargs': '+', 'choices': None,\n                        'default': ['cpp'], 'prog': 'format_code.py',\n                        'container': \u003cargparse._ArgumentGroup object at\n                        0x7f0a9d484b90\u003e, 'type': 'str', 'metavar': None}.\n  -x REGEX, --regex REGEX\n                        Custom regular expression to apply to the files that\n                        are to be fed to clang-format.\n  -i DIRS_IN [DIRS_IN ...], --dirs_in DIRS_IN [DIRS_IN ...]\n                        Sequence of directories. If given clang-format is\n                        going to run for source exclusively in these\n                        directories.\n  -o DIRS_OUT [DIRS_OUT ...], --dirs_out DIRS_OUT [DIRS_OUT ...]\n                        Sequence of directories. If given clang-format is\n                        going to ignore source files in these directories\n  -l, --lint            Check if clang-format reports no diffs (clean state).\n                        Execute only on files managed by git\n  -L, --lint_all        Check if clang-format reports no diffs (clean state).\n                        Checked files may or may not be managed by git\n  -p LINT_PATCHES [LINT_PATCHES ...], --lint_patches LINT_PATCHES [LINT_PATCHES ...]\n                        Check if clang-format reports no diffs (clean state).\n                        Check a list of patches, given sequentially after this\n                        flag\n  -b REFORMAT_BRANCH REFORMAT_BRANCH, --reformat_branch REFORMAT_BRANCH REFORMAT_BRANCH\n                        Reformat a branch given the \u003cstart\u003e and \u003cend\u003e commits.\n  -f, --format          Run clang-format against files managed by git\n  -F, --format_all      Run clang-format against files that may or may not be\n                        managed by the current git repository```\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbergercookie%2Fclang_git_format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbergercookie%2Fclang_git_format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbergercookie%2Fclang_git_format/lists"}