1.3 KiB
1.3 KiB
description
| description |
|---|
| Set up TCR (Test && Commit || Revert) for the current project |
TCR Setup
Set up TCR (Test && Commit || Revert) for practicing baby-step programming.
Steps
- Ensure git is initialized:
git init
- Create a TCR script:
cat > tcr.sh << 'EOF'
#!/bin/bash
# TCR: Test && Commit || Revert
# Replace with your actual test command
TEST_CMD="go test -v ./... || npm test"
echo "Running TCR..."
if $TEST_CMD; then
git add -A
git commit -m "TCR $(date +%H:%M:%S)"
echo "✅ Tests passed - Changes committed"
else
git restore .
echo "❌ Tests failed - Changes reverted"
fi
EOF
chmod +x tcr.sh
- Test it:
./tcr.sh
Usage
After making a tiny code change:
./tcr.sh
- If tests pass → Changes automatically committed
- If tests fail → Changes automatically reverted
Tips
- Start with refactoring only (not new features)
- Make the smallest possible changes
- When you get stuck (keep reverting), take a break
- Don't cheat with CTRL+Z to recover reverted code
Advanced: Watch Mode
Auto-run TCR on file changes:
# macOS with fswatch
fswatch -o src/ test/ | xargs -n1 -I{} ./tcr.sh
# Linux with inotifywait
while inotifywait -r -e modify src/ test/; do ./tcr.sh; done
Ask which test command to use, then create the TCR script and explain how to use it.