use crate::landing_location::LandingLocation;
use crate::repo_read_layout::{RepoLayout, git_path};
use crate::repository_location::RepositoryLocation;
use crate::rule_commit_sequencer::{SequencerFacts, SequencerState, sequencer_state};
use crate::worktree_identity::WorktreeIdentity;
pub fn location_of(layout: &RepoLayout) -> RepositoryLocation {
let identity: WorktreeIdentity = if layout.git_dir == layout.common_dir {
WorktreeIdentity::MainWorktree {
common_dir: layout.common_dir.clone(),
git_dir: layout.git_dir.clone(),
worktree_root: layout.worktree_root.clone(),
}
} else {
WorktreeIdentity::LinkedWorktree {
common_dir: layout.common_dir.clone(),
git_dir: layout.git_dir.clone(),
worktree_root: layout.worktree_root.clone(),
}
};
return RepositoryLocation { identity, prefix: layout.prefix.clone() };
}
pub fn landing_of(layout: &RepoLayout) -> Option<LandingLocation> {
return Some(LandingLocation {
git_dir: layout.git_dir.clone(),
index_path: git_path(layout, "index")?,
real_index_path: layout.git_dir.join("index"),
});
}
pub fn sequencer_of(layout: &RepoLayout) -> Option<SequencerState> {
let exists = |name: &str| -> Option<bool> {
let path = git_path(layout, name)?;
return Some(std::fs::symlink_metadata(path).is_ok());
};
return Some(sequencer_state(SequencerFacts {
merge_head: exists("MERGE_HEAD")?,
cherry_pick_head: exists("CHERRY_PICK_HEAD")?,
revert_head: exists("REVERT_HEAD")?,
}));
}
pub fn invocation_report(layout: &RepoLayout) -> Option<String> {
let lines: [String; 7] = [
layout.worktree_root.to_str()?.to_string(),
layout.git_dir.to_str()?.to_string(),
layout.common_dir.to_str()?.to_string(),
git_path(layout, "index")?.to_str()?.to_string(),
git_path(layout, "objects")?.to_str()?.to_string(),
git_path(layout, "cli-git-transactions")?.to_str()?.to_string(),
layout.object_format.name().to_string(),
];
return Some(lines.join("\n"));
}