Related Code Files:
safegit.py- Updated with full non-interactive supporttest_safegit_noninteractive.py- Comprehensive test suiteSAFEGIT_NONINTERACTIVE_ENHANCEMENT.md- Original proposal
SafeGIT now has complete non-interactive support for CI/CD pipelines, automated scripts, and batch operations.
--yes, -y # Auto-confirm safe operations (medium risk)
--force-yes # Force confirmation of ALL operations (use with caution!)
--non-interactive # Fail on any interactive prompt (for scripts)
--batch # Same as --non-interactiveSAFEGIT_NONINTERACTIVE=1 # Enable non-interactive mode
SAFEGIT_ASSUME_YES=1 # Auto-confirm safe operations
SAFEGIT_FORCE_YES=1 # Force all confirmations (dangerous!)
CI=1 # Auto-detected CI environmentsSupported CI platforms auto-detected:
- GitHub Actions (
GITHUB_ACTIONS) - GitLab CI (
GITLAB_CI) - Jenkins (
JENKINS_URL) - Travis CI (
TRAVIS) - Generic CI (
CI,CONTINUOUS_INTEGRATION)
The implementation intelligently handles different prompt types:
Type 'PROCEED'→ Auto-typesPROCEEDwith --force-yesType 'DELETE'→ Auto-typesDELETEwith --force-yesType 'MIRROR PUSH'→ Auto-typesMIRROR PUSHwith --force-yes- And 10+ other typed confirmations
[Y/n]→ Auto-respondsybased on danger level[y/N]→ Auto-respondsywith appropriate flags
[1/2/3]→ Auto-selects1(safest option) with --yes
# Safe operations (--yes sufficient)
safegit --yes add .
safegit --yes commit -m "message"
safegit --yes pull
# Medium risk (--yes or environment variable)
safegit --yes checkout -b new-branch
safegit --yes stash
# High risk (--force-yes required)
safegit --force-yes reset --hard
safegit --force-yes clean -fdx
safegit --force-yes push --forceNon-interactive operations are logged with:
- Mode (interactive/non-interactive)
- Flags used
- CI environment detection
- Timestamp and result
name: Deploy
on: push
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install SafeGIT
run: |
chmod +x safegit.py
sudo ln -s $(pwd)/safegit.py /usr/local/bin/safegit
- name: Commit changes
env:
SAFEGIT_ASSUME_YES: 1
run: |
safegit add .
safegit commit -m "Automated deployment"
safegit push#!/bin/bash
# Safe batch operations
export SAFEGIT_NONINTERACTIVE=1
export SAFEGIT_ASSUME_YES=1
for repo in repo1 repo2 repo3; do
cd $repo
safegit pull
safegit add -u
safegit commit -m "Batch update"
safegit push
done# This will FAIL without --force-yes
safegit --yes reset --hard # ❌ Blocked
# This will succeed
safegit --force-yes reset --hard # ✅ Auto-confirmed
# Environment variable approach
export SAFEGIT_FORCE_YES=1
safegit reset --hard # ✅ Auto-confirmedWhen operations are blocked, clear error messages explain why:
❌ ERROR: High-risk operation requires --force-yes flag
Prompt was: Type 'DELETE' to confirm:
❌ ERROR: Medium-risk operation requires --yes or --force-yes flag
Prompt was: Do you want to proceed? [y/N]:
❌ ERROR: Branch name confirmation requires manual input
Prompt was: Type the branch name to confirm:
Non-interactive mode works with dry-run:
safegit --dry-run --force-yes reset --hard
# Shows what would happen without executingRun the comprehensive test suite:
./test_safegit_noninteractive.pyTests cover:
- Safe operations with --yes
- Dangerous operations requiring --force-yes
- Environment variable support
- CI environment detection
- Dry-run mode
- Batch mode
- Error handling
- CI/CD Ready: SafeGIT can now be used in automated pipelines
- Scriptable: Batch operations are now possible
- Safe by Default: Dangerous operations still require explicit --force-yes
- Backwards Compatible: Interactive mode remains the default
- Comprehensive Logging: All automated operations are tracked
- Use --force-yes sparingly - It bypasses ALL safety checks
- Test in dry-run first - Use --dry-run to preview operations
- Check logs - Review
.git/safegit-log.jsonfor automated operations - CI detection - SafeGIT automatically detects CI environments
safegit --yes add .
safegit --yes commit -m "Update"
safegit --yes pushexport SAFEGIT_NONINTERACTIVE=1
export SAFEGIT_ASSUME_YES=1
# Now all safe operations proceed automatically# Only when absolutely necessary
safegit --force-yes reset --hard HEAD~1
safegit --force-yes clean -fdxSafeGIT now provides comprehensive non-interactive support while maintaining its core safety mission. The implementation follows the principle of "safe by default, dangerous by choice" - requiring explicit flags for risky operations even in automated environments.