use crate::child_environment::environment_value;
use crate::diagnostic_log::debug;
use crate::git_directory_roots::roots_for;
use crate::stale_ref_lock_judge::Judge;
use crate::stale_ref_locks::clear_stale_ref_locks;
use crate::worktree_add_plan::start_directory;
use std::ffi::OsString;
use std::path::PathBuf;
const TAG: &str = "cli-git";
pub fn is_covered(word: &[u8]) -> bool {
return word == b"fetch" || word == b"push";
}
pub fn forwarded_lock_notice(word: &[u8], global_prefix: &[OsString], environment: &[(OsString, OsString)], judge: &Judge) -> String {
if !is_covered(word) {
return String::new();
}
let Ok(current) = std::env::current_dir() else {
return String::new();
};
let Some(start) = start_directory(global_prefix, current.as_path()) else {
return String::new();
};
let named: Option<PathBuf> = environment_value(environment, "GIT_DIR").map(|path| { return start.join(path); });
let outcome = clear_stale_ref_locks(roots_for(start.as_path(), named).as_slice(), judge);
let notice: String = outcome.notice();
if !notice.is_empty() {
debug(TAG, "reference locks were judged before a forwarded fetch or push");
}
return notice;
}
#[cfg(test)]
#[path = "forwarded_lock_notice_tests.rs"]
mod tests;