summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-04-04 22:01:16 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-04-04 22:01:16 +0200
commit5843a6578480b33a321054d7ae133624c57286b1 (patch)
treea75982be48ff06562782bca8b52e152a9fac5b97
parent7475e89080d292cf995f805b3ca3e6dca11b8810 (diff)
Check that the git repo is personal before adding it as personal
-rw-r--r--src/git.rs41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/git.rs b/src/git.rs
index ea27add..ac92908 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -105,25 +105,46 @@ pub struct RepoMetadata {
}
pub fn list() -> Result<Vec<RepoMetadata>, ShackleError> {
- let mut results = Vec::new();
+ fn add_from_dir(
+ collection_dir: &PathBuf,
+ is_checking_group: bool,
+ ) -> Result<Vec<RepoMetadata>, ShackleError> {
+ let mut results = Vec::new();
+ if !collection_dir.is_dir() {
+ return Ok(results);
+ }
- let personal_dir = personal_git_dir()?;
- if personal_dir.is_dir() {
- for dir in personal_dir.read_dir()? {
+ for dir in collection_dir.read_dir()? {
let path = dir?.path();
let description_path = path.join("description");
let has_git_ext = path.extension().map_or(false, |ext| ext == "git");
- let has_description = description_path.is_file();
-
- // TODO: Read the config to tell if this is a shared repo
- if has_git_ext && has_description {
- let description = fs::read_to_string(description_path)?;
- results.push(RepoMetadata { path, description });
+ if has_git_ext {
+ if let Ok(repo) = Repository::open_bare(&path) {
+ let config = repo.config()?.snapshot()?;
+ let shared_config = config.get_str("core.sharedRepository").ok(); // TODO: Could shis fail for other reasons?
+ let is_group_shared =
+ [Some("group"), Some("1"), Some("true")].contains(&shared_config);
+
+ if is_group_shared == is_checking_group {
+ let description = if description_path.is_file() {
+ fs::read_to_string(description_path)?
+ } else {
+ String::new()
+ };
+
+ results.push(RepoMetadata { path, description });
+ }
+ }
}
}
+ Ok(results)
}
+ let mut results = Vec::new();
+
+ results.append(&mut add_from_dir(&personal_git_dir()?, false)?);
+
// TODO: Do the same (more or less) for group repos
Ok(results)