Skip to content

feat(cli): support user-defined templates for --init - #1583

Open
lazizbekravshanov wants to merge 1 commit into
orhun:mainfrom
lazizbekravshanov:issue-412-user-defined-templates
Open

feat(cli): support user-defined templates for --init#1583
lazizbekravshanov wants to merge 1 commit into
orhun:mainfrom
lazizbekravshanov:issue-412-user-defined-templates

Conversation

@lazizbekravshanov

Copy link
Copy Markdown

Description

Adds support for user-defined --init templates, alongside the existing built-in templates:

  • --templates-dir <PATH> (env: GIT_CLIFF_TEMPLATES_DIR) — a directory of user .toml templates that --init <name> can use. A user template overrides a built-in template of the same name.
  • --list-templates — prints all available template names (built-in + user-defined), one per line, sorted and deduplicated. This covers the completion use case from the issue.

Behavior details:

  • Existing --init behavior is unchanged when no --templates-dir is given.
  • A missing or non-directory --templates-dir is a clear error naming the offending path; non-.toml files in the directory are ignored.
  • --list-templates prints and exits (like --init), and works outside a git repository.
  • Tera body-templates (--body / --template) are unaffected — this only concerns the --init config presets.

Motivation and Context

Closes #412. Users who keep their own --init template presets currently can't use them through git-cliff's built-in mechanism, and there was no way to enumerate the available templates (needed for shell/editor completion).

How Has This Been Tested?

  • Unit tests (test-first / TDD):
    • git-cliff-core (embed.rs): built-in listing (sorted, no extension); merging a user directory (ignoring non-.toml, deduped); user template overriding a built-in; .toml extension normalization; and a clear error when the directory is missing.
    • git-cliff (args.rs, lib.rs): parsing --templates-dir / --list-templates; init_config writing the user template (and falling back to the built-in).
  • cargo test (workspace): all green.
  • cargo +nightly fmt --all -- --check: clean.
  • cargo clippy --tests -- -D warnings: clean on the changed code. (Note: on my local toolchain — rustc 1.97.0 — clippy also reports one pre-existing useless_borrows_in_formatting lint in git-cliff-core/src/repo.rs, which is unrelated to this change and outside the diff.)
  • Manual end-to-end on the built binary: listing built-ins; merging + overriding via --templates-dir; the GIT_CLIFF_TEMPLATES_DIR env var; --init <name> --templates-dir writing user content; the missing-directory error; and confirming both commands work outside a git repository.

Types of Changes

  • New feature (non-breaking change which adds functionality)
  • Documentation (no code change)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (if applicable).
  • I have formatted the code with rustfmt.
    • cargo +nightly fmt --all
  • I checked the lints with clippy.
    • cargo clippy --tests --verbose -- -D warnings
  • I have added tests to cover my changes.
  • All new and existing tests passed.
    • cargo test

@lazizbekravshanov
lazizbekravshanov requested a review from orhun as a code owner July 13, 2026 04:58
@welcome

welcome Bot commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@lazizbekravshanov

Copy link
Copy Markdown
Author

Quick heads-up on the red "Test suite" check: the failure is in the Codecov upload step, not the tests. The uploader couldn't verify its own GPG signature (gpg: Can't check signature: No public key → "Could not verify signature"), which looks like a transient Codecov/keyserver issue — the test job itself passes and the other checks are green. A re-run should clear it whenever convenient. Happy to adjust anything on my end if needed!

@lazizbekravshanov

Copy link
Copy Markdown
Author

Hi @orhun — gentle nudge on this one whenever you have a moment 🙂 It implements #412 (which you'd approved): --templates-dir <PATH> + GIT_CLIFF_TEMPLATES_DIR, --list-templates, and user templates overriding the built-ins, all TDD'd (10 unit tests + behavioural coverage). The branch is still MERGEABLE and rebased on main.

Just to re-flag: the one red "Test suite" check is the Codecov upload step failing to verify its own GPG signature (a transient uploader/keyserver issue), not the tests — the actual test job and the other 107 checks are green. Happy to rebase, adjust the flag/UX, or split anything out if that helps review. No rush at all, and thanks for your time!

@lazizbekravshanov

Copy link
Copy Markdown
Author

Hi @orhun, following up on this one. It implements #412 (user-defined templates for --init): the --templates-dir <PATH> flag, the GIT_CLIFF_TEMPLATES_DIR env var, and --list-templates, with user templates overriding the built-ins. Tests, clippy, and fmt are green (the one red check is the codecov upload step, an infra flake that also fails on main). Happy to rebase or adjust anything whenever you get a chance to look.

Add `--templates-dir <PATH>` (env: GIT_CLIFF_TEMPLATES_DIR) so `--init`
can look up user-defined templates, and `--list-templates` to print all
available template names (built-in and user-defined) for shell/editor
completion. A user template overrides a built-in template of the same name.

Closes orhun#412
@lazizbekravshanov
lazizbekravshanov force-pushed the issue-412-user-defined-templates branch from 3e0fb4b to 84b587c Compare July 30, 2026 17:09
Copilot AI review requested due to automatic review settings July 30, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lazizbekravshanov

Copy link
Copy Markdown
Author

Closing this to clear my queue. The branch stays on my fork, so if you would still like the templates feature I am glad to reopen and rebase it whenever.

@orhun orhun reopened this Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add flags and options to support user-defined templates

3 participants