diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-04-02 21:04:52 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-04-02 21:04:52 +0200 |
commit | e5fef4f81679582cd6e55de3c8d4461fe712c997 (patch) | |
tree | d3455653f52261db8ccc0b42841a8d953f5d494b /src/git.rs | |
parent | 3a0452fb06c116de61ae75cf34931d4747c5953f (diff) |
Start the basics of listing repos
Diffstat (limited to 'src/git.rs')
-rw-r--r-- | src/git.rs | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -3,7 +3,7 @@ use crate::{ ShackleError, }; use git2::{Repository, RepositoryInitMode, RepositoryInitOptions}; -use std::{path::PathBuf, process::Command}; +use std::{fs, path::PathBuf, process::Command}; use user_info::{get_user_groups, get_username}; pub struct GitInitResult { @@ -99,6 +99,36 @@ pub fn init(repo_name: &str, group: &Option<String>) -> Result<GitInitResult, Sh } } +pub struct RepoMetadata { + pub path: PathBuf, + pub description: String, +} + +pub fn list() -> Result<Vec<RepoMetadata>, ShackleError> { + let mut results = Vec::new(); + + let personal_dir = personal_git_dir()?; + if personal_dir.is_dir() { + for dir in personal_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 }); + } + } + } + + // TODO: Do the same (more or less) for group repos + + Ok(results) +} + pub fn upload_pack(upload_pack_args: &GitUploadPackArgs) -> Result<(), ShackleError> { if !is_valid_git_repo_path(&upload_pack_args.directory)? { return Err(ShackleError::InvalidDirectory); |