use crate::error::{DealerError, DealerResult};
use crate::state::DealerState;
use crate::support::git::ResolvedGitRev;
pub(crate) fn resolve_git_dependency(
) -> DealerResult<PathBuf> {
let rev_str = match rev {
ResolvedGitRev::Tag(t) => t.clone(),
ResolvedGitRev::Branch(b) => b.clone(),
.join(crate::constants::dirs::GIT_DIR)
let source_dir = pkg_dir.join(crate::constants::dirs::SOURCE_DIR);
let lock_file = pkg_dir.join("lock");
fs::create_dir_all(&pkg_dir).map_err(|e| DealerError::io(&pkg_dir, e))?;
let f = fs::File::create(&lock_file).map_err(|e| DealerError::io(&lock_file, e))?;
let mut lock = fd_lock::RwLock::new(f);
.map_err(|e| DealerError::Package(format!("failed to lock cache: {e}")))?;
let temp_source_dir = pkg_dir.join("temp_source");
if temp_source_dir.exists() {
fs::remove_dir_all(&temp_source_dir).ok();
// Fetch and checkout using gix
crate::support::git::materialize_git_source(url, rev, &temp_source_dir)
.map_err(|e| DealerError::Package(format!("git checkout failed: {e}")))?;
fs::rename(&temp_source_dir, &source_dir).map_err(|e| DealerError::io(&source_dir, e))?;