Skip to content

Add --dry-run flag to destructive operations #14

@UtsavBalar1231

Description

@UtsavBalar1231

Problem

Only clean and push commands have --dry-run mode. Other destructive operations lack preview capability, making them risky.

Missing Dry-Run Support

  • reset --hard - No preview of what will be reverted
  • revert - No preview of changes
  • merge - No preview of merge outcome
  • checkout - No preview of file changes
  • restore - No preview of what will be restored

Impact

  • Risky operations without preview
  • Users can't verify effects before executing
  • Increased chance of accidental data loss
  • Poor UX compared to modern tools

Approach

1. Add --dry-run Flag:

#[derive(Parser)]
pub struct ResetArgs {
    #[arg(long)]
    dry_run: bool,
    // ... other args
}

2. Implement Preview Logic:

if args.dry_run {
    // Show what would happen
    println!("Would reset the following files:");
    for file in files_to_reset {
        println!("  {}", file.display());
    }
    println!("\nRun without --dry-run to execute");
    return Ok(());
}

3. Preview Information:

  • Files that would be modified
  • Files that would be deleted
  • Unstaged/uncommitted changes that would be lost
  • Commit range that would be affected

4. Consistent Output Format:
Create helper for dry-run output:

fn preview_changes(action: &str, files: &[PathBuf]) {
    println!("{}: {} files would be {}", 
             "Dry run".yellow().bold(), 
             files.len(), 
             action);
    for file in files {
        println!("  {} {}", "→".dim(), file.display());
    }
}

Priority by Command

  1. High: reset --hard (most destructive)
  2. High: checkout (can overwrite files)
  3. Medium: revert, merge (complex operations)
  4. Low: restore (usually intentional)

Test Cases

  • Each command with --dry-run shows preview
  • Verify no actual changes made in dry-run mode
  • Verify same logic used for preview and execution

References

  • rsync --dry-run as gold standard
  • git rm --dry-run, git clean --dry-run
  • Consider adding --interactive mode for some commands

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority: mediumMedium priority - normal timeline

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions