Unified · Split
| @@ -94,8 +94,8 @@ fn create_dir(p: &Path) -> Result<(), Error> { · 93 unmodified lines | |||
| 94 | fs::create_dir_all(p).map_err(|e| Error::CreateDirectory(e, p.to_owned())) | 94 | fs::create_dir_all(p).map_err(|e| Error::CreateDirectory(e, p.to_owned())) |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | pub fn repository(directory: Option<PathBuf>) -> Result<(), Error> { | 97 | pub fn repository(directory: impl Into<PathBuf>) -> Result<(), Error> { |
| 98 | let mut cursor = directory.unwrap_or_default(); | 98 | let mut cursor = directory.into(); |
| 99 | cursor.push(GIT_DIR_NAME); | 99 | cursor.push(GIT_DIR_NAME); |
| 100 | 100 | ||
| 101 | if cursor.is_dir() { | 101 | if cursor.is_dir() { |
| @@ -6,7 +6,7 @@ mod init { · 5 unmodified lines | |||
| 6 | /// Really just a sketch at this point to help guide the API. | 6 | /// Really just a sketch at this point to help guide the API. |
| 7 | pub fn create_and_init(directory: impl AsRef<Path>) -> Result<Self, crate::init::Error> { | 7 | pub fn create_and_init(directory: impl AsRef<Path>) -> Result<Self, crate::init::Error> { |
| 8 | // TODO: proper error | 8 | // TODO: proper error |
| 9 | crate::init::repository(Some(directory.as_ref().to_owned()))?; | 9 | crate::init::repository(directory.as_ref())?; |
| 10 | Ok(Repository::discover(directory).unwrap()) // TODO: a specialized method without discovery | 10 | Ok(Repository::discover(directory).unwrap()) // TODO: a specialized method without discovery |
| 11 | } | 11 | } |
| 12 | } | 12 | } |
| @@ -2,5 +2,5 @@ use anyhow::{Context as AnyhowContext, Result}; · 1 unmodified line | |||
| 2 | use std::path::PathBuf; | 2 | use std::path::PathBuf; |
| 3 | 3 | ||
| 4 | pub fn init(directory: Option<PathBuf>) -> Result<()> { | 4 | pub fn init(directory: Option<PathBuf>) -> Result<()> { |
| 5 | git_repository::init::repository(directory).with_context(|| "Repository initialization failed") | 5 | git_repository::init::repository(directory.unwrap_or_default()).with_context(|| "Repository initialization failed") |
| 6 | } | 6 | } |