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-categories in [tool.repomatic].

repomatic.gitignore.GITIGNORE_IO_URL = 'https://www.toptal.com/developers/gitignore/api'

gitignore.io API endpoint for fetching .gitignore templates.

repomatic.gitignore.build_gitignore(config)[source]

Fetch and assemble the .gitignore content for config.

Combines GITIGNORE_BASE_CATEGORIES with 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:

str

Returns:

The full .gitignore text.

Raises:

repomatic.http.FetchError – When the gitignore.io fetch fails.

repomatic.gitignore.parse_rules(content)[source]

Extract the ignore rules from .gitignore content.

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.

Parameters:

content (str) – Full text of a .gitignore file.

Return type:

list[str]

Returns:

The rules, in first-seen order.

repomatic.gitignore.orphaned_rules(existing, generated)[source]

Return the rules generated would drop from existing.

sync-gitignore rebuilds the file from gitignore.io plus [tool.repomatic.gitignore] extra-content and 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 .gitignore on disk.

  • generated (str) – Content build_gitignore() just produced.

Return type:

list[str]

Returns:

Rules present in existing and absent from generated, in first-seen order. Empty when the sync drops nothing.