use crate::check::Outcome;
use super::common;
const MB: u64 = 1024 * 1024;
pub fn staged() -> Outcome {
let warn_mb = crate::config::integer_or("amont.largeFileWarn", 10, 1..=1_000_000) as u64;
let block_mb = crate::config::integer_or("amont.largeFileBlock", 100, 1..=1_000_000) as u64;
let root = common::repo_root();
let mut blocked = false;
let mut warned = false;
for f in common::staged_files(&[]) {
let path = std::path::Path::new(&root).join(&f);
let Ok(meta) = std::fs::metadata(&path) else {
continue; };
if !meta.is_file() {
continue;
}
let mb = meta.len() / MB;
if meta.len() >= block_mb * MB {
blocked = true;
common::fail(&format!(
"large-files: {} is {mb} MB — over the {block_mb} MB limit \
(GitHub refuses these at push). Use git-lfs, or keep it out \
of history: deletion later does not remove the bytes",
crate::ui::sanitize(&f),
));
} else if meta.len() >= warn_mb * MB {
warned = true;
common::warn(&format!(
"large-files: {} is {mb} MB — every future clone pays for \
this forever (git config amont.largeFileWarn to tune)",
crate::ui::sanitize(&f),
));
}
}
if blocked {
return Outcome::Failed;
}
if warned {
return Outcome::Warned;
}
common::ok("No oversized files staged");
Outcome::Passed
}