diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-04-05 19:44:52 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-04-05 19:44:52 +0200 |
commit | b11d2e3676e96e25e170c99e7fa03dd39e0c403c (patch) | |
tree | 574b9aff464483fd1e16df3ec05e04974d1c7976 /src | |
parent | 5843a6578480b33a321054d7ae133624c57286b1 (diff) |
Add group git dirs to the listing
Diffstat (limited to 'src')
-rw-r--r-- | src/git.rs | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -19,13 +19,13 @@ fn personal_git_dir() -> Result<PathBuf, ShackleError> { Ok(git_dir_prefix().join(username)) } -fn group_git_dir(group: &str) -> Result<PathBuf, ShackleError> { - let groups = get_user_groups(); - if !groups.iter().any(|g| g == group) { - Err(ShackleError::InvalidGroup) - } else { - Ok(git_dir_prefix().join(group)) - } +fn verify_user_is_in_group(group: &str) -> bool { + let user_groups = get_user_groups(); + user_groups.iter().any(|g| g == group) +} + +fn group_git_dir(group: &str) -> PathBuf { + git_dir_prefix().join(group) } fn is_valid_git_repo_path(path: &PathBuf) -> Result<bool, ShackleError> { @@ -67,7 +67,11 @@ fn is_valid_git_repo_path(path: &PathBuf) -> Result<bool, ShackleError> { pub fn init(repo_name: &str, group: &Option<String>) -> Result<GitInitResult, ShackleError> { fn init_group(repo_name: &str, group: &str) -> Result<GitInitResult, ShackleError> { - let path = group_git_dir(group)?.join(repo_name).with_extension("git"); + if !verify_user_is_in_group(group) { + return Err(ShackleError::InvalidGroup); + } + + let path = group_git_dir(group).join(repo_name).with_extension("git"); Repository::init_opts( &path, @@ -144,8 +148,10 @@ pub fn list() -> Result<Vec<RepoMetadata>, ShackleError> { 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 + let groups = get_user_groups(); + for group in &groups { + results.append(&mut add_from_dir(&group_git_dir(&group), true)?); + } Ok(results) } |