https://github.com/lorenzwalthert/gitignore-tidy
Re-order and clean .gitignore files
https://github.com/lorenzwalthert/gitignore-tidy
Last synced: 5 months ago
JSON representation
Re-order and clean .gitignore files
- Host: GitHub
- URL: https://github.com/lorenzwalthert/gitignore-tidy
- Owner: lorenzwalthert
- License: mit
- Created: 2021-12-25T21:35:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-15T14:13:26.000Z (about 1 year ago)
- Last Synced: 2024-05-02T02:24:30.546Z (12 months ago)
- Language: Python
- Homepage:
- Size: 91.8 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - lorenzwalthert/gitignore-tidy - Re-order and clean .gitignore files (Python)
README
# Tidy up your `.gititnore` files
This little python package exposes one command line executable and [pre-commit hook](https://pre-commit.com) that can be used to tidy up a `.gitignore` file. It does
* remove leading or trailing white space (unless `--allow-leading-white-space` is set).
* remove duplicate entries.
* allow at most one blank line before comments.
* order entries while respecting that [negating entries](https://git-scm.com/docs/gitignore#_pattern_format) must always go *after* non-negating entries, e.g.```
a/
!a/b
```**Caution**
Sorting while preserving the pattern is complex in some cases. If you have
negating entries and wild-cards that are not at the end of the line within
the same section, running the current version may change your `.gitignore`
pattern and we advise against using this program in that case!
We might revisit the algoritm in the future to fix it for these cases:```
# my first section
*csv
!*aut.csv# another
```
Swapping the first two entries in the first section will change the exclusion pattern (just put `a.csv` and `aut.csv` into your repo to see why).## CLI
```bash
gitignore-tidy # in repo root
```## pre-commit hook
In your `.pre-commit-config.yaml`:
```yaml
- repo: https://github.com/lorenzwalthert/gitignore-tidy
rev: bb80136de68e7fe844cd0397f0088f469845d258.
hooks:
- id: tidy-gitignore
# args: [--allow-leading-whitespace]
```And run `pre-commit autopudate` to get the latest hook version.