Usage¶
Snippet Markers¶
Add markers to your markdown files to indicate where snippets should be inserted:
# My Project
<!-- SNIPPET-START: license-notice -->
This content will be replaced with the contents of `license-notice.md` from your snippet repo.
<!-- SNIPPET-END -->
## Other content...
The snippet name (license-notice in this example) corresponds to a file in your snippet repository (license-notice.md).
Command Line Options¶
--dry-run¶
Preview changes without modifying files.
--verbose, -v¶
Print info-level logs showing files being processed and updates.
--debug¶
Print debug-level logs with timestamps, commands, and hash values.
Examples¶
Normal Run¶
No output if all snippets are up to date.
Preview Changes¶
Verbose Output¶
$ pre-commit-snippets --verbose
Snippet repo: https://github.com/your-org/snippets.git
Target files: README.md, CONTRIBUTING.md
Processing README.md
Updating snippet 'license-notice' in README.md
Processing CONTRIBUTING.md
All snippets are up to date
Staged modified files
Debug Output¶
$ pre-commit-snippets --debug
2024-01-15 10:30:00 [DEBUG] pre_commit_snippet: Starting pre-commit-snippets
2024-01-15 10:30:00 [DEBUG] pre_commit_snippet: Running command: git rev-parse --show-toplevel
2024-01-15 10:30:00 [DEBUG] pre_commit_snippet: Repository root: /home/user/project
...
How It Works¶
- Clone: Shallow clones the snippet repository to a temporary directory
- Parse: Finds all
SNIPPET-START/SNIPPET-ENDmarker pairs in target files - Compare: Computes SHA-256 hashes to detect changes
- Replace: Updates blocks only when the snippet has changed
- Cache: Saves hashes to avoid recomputing on the next run
- Stage: Automatically stages modified files for commit
- Cleanup: Removes the temporary clone