summaryrefslogtreecommitdiff
path: root/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/git.rs b/src/git.rs
index 7337a6a..ea27add 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -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);