use crate::{bare::GitBare, cmd::oid::ObjectId, errors::GitResult};

impl GitBare {
    pub fn mergehead_list(&self) -> GitResult<Vec<ObjectId>> {
        let merge_head_path = self.bare_dir.canonicalize()?.join("MERGE_HEAD");

        if !merge_head_path.exists() {
            return Ok(Vec::new());
        }

        let content = std::fs::read_to_string(&merge_head_path)?;
        let oids: Vec<ObjectId> = content
            .lines()
            .filter(|line| !line.trim().is_empty())
            .map(|line| ObjectId::new(line.trim()))
            .collect();

        Ok(oids)
    }
}
