From db131014cf9d40f526a42d14901f3c10cba27786 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Tue, 28 Feb 2023 22:54:04 +0200 Subject: Git init --- src/git.rs | 19 +++++++++++++++++++ src/main.rs | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/git.rs (limited to 'src') diff --git a/src/git.rs b/src/git.rs new file mode 100644 index 0000000..bd26568 --- /dev/null +++ b/src/git.rs @@ -0,0 +1,19 @@ +use crate::ShackleError; + +use git2::{Repository, RepositoryInitOptions}; +use std::path::PathBuf; + +pub fn init(repo_name: &str) -> Result<(), ShackleError> { + let mut path = PathBuf::from("git"); + path.push(repo_name); + path.set_extension("git"); + + Repository::init_opts( + path, + &RepositoryInitOptions::new() + .bare(true) + .mkdir(true) + .no_reinit(true), + )?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 0df2754..142b4fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::{io, io::Write}; use thiserror::Error; +mod git; mod parser; use parser::Command; @@ -31,6 +32,7 @@ fn main() -> Result<(), ShackleError> { break; } Ok(Command::GitInit(repo_name)) => { + git::init(&repo_name)?; // TODO should report this error differently println!("Successfully created {}.git", repo_name); } } @@ -39,7 +41,9 @@ fn main() -> Result<(), ShackleError> { } #[derive(Error, Debug)] -enum ShackleError { +pub enum ShackleError { #[error(transparent)] IoError(#[from] io::Error), + #[error(transparent)] + GitError(#[from] git2::Error), } -- cgit v1.2.3