repomatic.gitignore module¶
Generate .gitignore content from gitignore.io templates.
Backs the sync-gitignore command: fetches the base template categories plus
any [tool.repomatic] gitignore.extra-categories from gitignore.io, then
appends gitignore.extra-content.
- repomatic.gitignore.GITIGNORE_BASE_CATEGORIES: tuple[str, ...] = ('certificates', 'emacs', 'git', 'gpg', 'linux', 'macos', 'node', 'nohup', 'python', 'rust', 'ssh', 'vim', 'virtualenv', 'visualstudiocode', 'windows')¶
Base gitignore.io template categories included in every generated
.gitignore.These cover common development environments, operating systems, and tools. Downstream projects can add more via
gitignore.extra-categoriesin[tool.repomatic].
- repomatic.gitignore.GITIGNORE_IO_URL = 'https://www.toptal.com/developers/gitignore/api'¶
gitignore.io API endpoint for fetching
.gitignoretemplates.
- repomatic.gitignore.build_gitignore(config)[source]¶
Fetch and assemble the
.gitignorecontent for config.Combines
GITIGNORE_BASE_CATEGORIESwith the configured extra categories (order-preserving, deduplicated), fetches the merged template from gitignore.io, and appends the configured extra content.- Parameters:
config (
Config) – The resolved[tool.repomatic]configuration.- Return type:
- Returns:
The full
.gitignoretext.- Raises:
repomatic.http.FetchError – When the gitignore.io fetch fails.
- repomatic.gitignore.parse_rules(content)[source]¶
Extract the ignore rules from
.gitignorecontent.Blank lines and comments are dropped, leaving only the lines git actually matches paths against. Order is preserved and duplicates are collapsed, so the result compares two files by what they ignore rather than by how they are laid out.
Only a leading
#opens a comment: git treats one anywhere else in the line as part of the pattern, so no inline-comment stripping happens here.
- repomatic.gitignore.orphaned_rules(existing, generated)[source]¶
Return the rules generated would drop from existing.
sync-gitignorerebuilds the file from gitignore.io plus[tool.repomatic.gitignore] extra-contentand never reads what is already on disk, so a rule added by hand survives exactly one edit: the next sync writes over it. Comparing the two rule sets before the write is what turns that silent loss into something the caller can refuse.- Parameters:
existing (
str) – Current content of the.gitignoreon disk.generated (
str) – Contentbuild_gitignore()just produced.
- Return type:
- Returns:
Rules present in existing and absent from generated, in first-seen order. Empty when the sync drops nothing.