What problem does it solve?
TCR (Test && Commit || Revert) enforces extremely small, atomic code changes by automatically committing passing tests and reverting failing ones. This practice cultivates discipline, ensures high test coverage, and provides immediate feedback on development fatigue, leading to more robust code and a sustainable pace.
Core Features & Use Cases
- Automated Commit/Revert: Forces "baby steps" by committing code only if tests pass, and reverting if they fail.
- Failure Documentation: Prompts users to log failures, turning every revert into a valuable learning opportunity for pattern recognition.
- TRC Variant: Supports the "Red" phase of TDD by committing on test failure and reverting on pass, ensuring tests are written correctly.
- Use Case: A developer is refactoring a complex function. Using TCR, they make a tiny change, run tests, and if they pass, the change is automatically committed. If tests fail, the code reverts, forcing them to rethink and make an even smaller, safer step, leading to higher quality and less fear of breaking existing functionality.
Quick Start
Basic TCR script (save as tcr.sh and make executable)
<your test command> && git commit -am "TCR $(date +%H:%M:%S)" || git restore.
Example failure documentation (add to TCR-LEARNINGS.md)
TCR Learnings
## Failure Patterns
- Combining extraction + rename: Always fails - do separately
- Refactoring without reading tests first: 70% failure rate