summaryrefslogtreecommitdiff
path: root/src/git.rs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-03-29 22:59:57 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-03-29 23:01:47 +0200
commit745cd8ab27480a3cf516a2684db2c4fd7cf2144c (patch)
treefeb950d52c3289b5112b81e3d3d6a79f0c94cb49 /src/git.rs
parent87da80d972c00358b46172ec9661e6a3a307a0a5 (diff)
Check user group when creating shared repos
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/git.rs b/src/git.rs
index c61bec1..dcdb71b 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -7,7 +7,7 @@ use std::{
path::{Path, PathBuf},
process::Command,
};
-use user_info::get_username;
+use user_info::{get_user_groups, get_username};
pub struct GitInitResult {
pub path: PathBuf,
@@ -18,8 +18,13 @@ fn personal_git_dir() -> Result<PathBuf, ShackleError> {
Ok(Path::new("git").join(username))
}
-fn group_git_dir(group: &str) -> PathBuf {
- Path::new("git").join(group)
+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(Path::new("git").join(group))
+ }
}
fn is_valid_personal_git_repo(path: &PathBuf) -> Result<bool, ShackleError> {
@@ -42,7 +47,7 @@ fn is_valid_personal_git_repo(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");
+ let path = group_git_dir(group)?.join(repo_name).with_extension("git");
Repository::init_opts(
&path,