Files
tour/src/rm.rs
Adam French 507c61fe5f Fix bugs and improve robustness across the codebase
- Fix staged files being silently cleared when commit uses inline files
- Refactor step navigation to use direct go_to_step instead of fragile delta math
- Change step numbers from i32 to u32 (reject negative values at parse time)
- Add tour rm command to mark files for removal during carry-forward
- Add tour reset command to clear session and remove tracked files
- Consolidate duplicate recursive copy functions into shared copy_tree in utils
- Validate step directories are sequential (detect corruption)
- Detect binary files in diffs instead of showing garbage
- Use /// doc comments on enum variants so clap generates proper help text
- Remove custom Help subcommand in favor of clap's built-in --help
- Add CorruptedTour error variant for integrity checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 21:23:39 +00:00

45 lines
1.2 KiB
Rust

use crate::error::TourError;
use crate::utils::require_tour;
use std::collections::HashSet;
use std::fs::{self, OpenOptions};
use std::io::Write;
use std::path::PathBuf;
pub const REMOVED_PATH: &str = "./.tour/removed";
pub fn rm(files: Vec<PathBuf>) -> Result<(), TourError> {
require_tour()?;
let existing = get_removed()?;
let existing_set: HashSet<PathBuf> = existing.into_iter().collect();
let mut removed_file = OpenOptions::new()
.append(true)
.create(true)
.open(REMOVED_PATH)?;
for file in &files {
if existing_set.contains(file) {
println!("already marked for removal: {}", file.display());
} else {
writeln!(removed_file, "{}", file.display())?;
println!("marked for removal: {}", file.display());
}
}
Ok(())
}
pub fn get_removed() -> Result<Vec<PathBuf>, std::io::Error> {
let content = fs::read_to_string(REMOVED_PATH).unwrap_or_default();
Ok(content
.lines()
.filter(|l| !l.is_empty())
.map(PathBuf::from)
.collect())
}
pub fn clear_removed() -> Result<(), std::io::Error> {
fs::write(REMOVED_PATH, "")
}