Add staged files (so random files don't get removed)

This commit is contained in:
2026-03-03 11:16:22 +00:00
parent c0a71bc285
commit 399a72f380
5 changed files with 141 additions and 28 deletions

View File

@@ -1,3 +1,4 @@
use crate::add::{clear_staged, get_staged};
use crate::error::CommitError;
use crate::utils::{copy_path, is_descendant_of_current_dir, is_file_in_dir};
use crate::TOUR_DIR;
@@ -7,6 +8,16 @@ use std::path::{Path, PathBuf};
pub fn commit(files: Vec<PathBuf>, message: String) -> Result<(), CommitError> {
let tour_dir = Path::new(TOUR_DIR);
let files = if files.is_empty() {
let staged = get_staged()?;
if staged.is_empty() {
return Err(CommitError::NothingToCommit);
}
staged
} else {
files
};
for file in &files {
if !is_descendant_of_current_dir(file)? {
return Err(CommitError::NotADescendantOfCurrentDir(file.clone()));
@@ -30,6 +41,7 @@ pub fn commit(files: Vec<PathBuf>, message: String) -> Result<(), CommitError> {
}
fs::write(step_dir.join("message"), &message)?;
clear_staged()?;
crate::info::update_last_modified()?;
println!("Step {}: {}", step_num, message);