diff options
| author | Bond_009 <bond.009@outlook.com> | 2020-11-16 23:05:09 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2020-11-16 23:05:09 +0100 |
| commit | db2ed2b36776f1093d67d212bc3295f148039c0d (patch) | |
| tree | 4e23ea8ad65aed796296ebc52d79a48a03ec55ba /src | |
| parent | 70938201e78791c8c8dd608419904549449909c4 (diff) | |
Add ability to set description
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 7 | ||||
| -rw-r--r-- | src/utils.rs | 13 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 5b65148..e4b2dde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,8 +61,7 @@ fn main() { } fn get_config(config: Option<&str>) -> Config { - let config_path = match config - { + let config_path = match config { Some(c) => Cow::Borrowed(c), None => match env::var("GIT_MIRROR_CONFIG") { Ok(c) => Cow::Owned(c), @@ -89,6 +88,10 @@ fn get_config(config: Option<&str>) -> Config { fn init(path: &Path, project: &ProjectConfig) -> Result<(), git2::Error> { let _repo = Repository::clone(&project.url, path)?; + if let Some(d) = &project.description { + utils::set_description(path, d).unwrap(); + } + Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 6e737aa..f7c31be 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,9 @@ +use std::{ + fs::File, + io::{Result, Write}, + path::Path +}; + pub fn get_repo_name(url: &str) -> &str { let start = url.rfind('/').unwrap_or_default() + 1; if url.ends_with(".git") @@ -8,6 +14,13 @@ pub fn get_repo_name(url: &str) -> &str { &url[start..] } +pub fn set_description(path: &Path, description: &str) -> Result<()> { + let mut path_buf = path.to_path_buf(); + path_buf.push(".git/description"); + let mut file = File::create(&path_buf)?; + file.write_all(description.as_bytes()) +} + #[cfg(test)] mod tests { use super::*; |
