summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-04-07 11:59:25 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-04-07 11:59:25 +0200
commitc21d81998d3cf573a4b0333f81c22494906cb111 (patch)
tree4e3b1e0bc2138d9f35403d5fdd2b7b0afa19317e /src
parent108fef99d19ade71013dc25562e3c3c3e23347ef (diff)
Set the description while initting the repo
This should work, but doesn't seem to.
Diffstat (limited to 'src')
-rw-r--r--src/git.rs50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/git.rs b/src/git.rs
index 1271712..82f32dd 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -70,41 +70,45 @@ pub fn init(
group: &Option<String>,
description: &Option<String>,
) -> Result<GitInitResult, ShackleError> {
- fn init_group(repo_name: &str, group: &str) -> Result<GitInitResult, ShackleError> {
+ fn init_group_opts(
+ repo_name: &str,
+ group: &str,
+ ) -> Result<(PathBuf, RepositoryInitOptions), ShackleError> {
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,
- &RepositoryInitOptions::new()
- .bare(true)
- .mode(RepositoryInitMode::SHARED_GROUP)
- .mkdir(true)
- .no_reinit(true),
- )?;
- Ok(GitInitResult { path })
+ let mut init_opts = RepositoryInitOptions::new();
+ init_opts
+ .bare(true)
+ .mode(RepositoryInitMode::SHARED_GROUP)
+ .mkdir(true)
+ .no_reinit(true);
+
+ Ok((path, init_opts))
}
- fn init_personal(repo_name: &str) -> Result<GitInitResult, ShackleError> {
+ fn init_personal_opts(
+ repo_name: &str,
+ ) -> Result<(PathBuf, RepositoryInitOptions), ShackleError> {
let path = personal_git_dir()?.join(repo_name).with_extension("git");
+ let mut init_opts = RepositoryInitOptions::new();
+ init_opts.bare(true).mkdir(true).no_reinit(true);
- Repository::init_opts(
- &path,
- &RepositoryInitOptions::new()
- .bare(true)
- .mkdir(true)
- .no_reinit(true),
- )?;
- Ok(GitInitResult { path })
+ Ok((path, init_opts))
}
- match group {
- Some(group) => init_group(repo_name, group),
- None => init_personal(repo_name),
+ let (path, mut init_opts) = match group {
+ Some(group) => init_group_opts(repo_name, group)?,
+ None => init_personal_opts(repo_name)?,
+ };
+ if let Some(description) = description {
+ init_opts.description(description);
}
+
+ Repository::init_opts(&path, &init_opts)?;
+ Ok(GitInitResult { path })
}
pub struct RepoMetadata {