From 61c5b5b3a1b84692f3cba468a828a5493f7ff43b Mon Sep 17 00:00:00 2001 From: Tomoaki Ichige Date: Sat, 22 Jul 2023 05:49:29 +0900 Subject: [PATCH 1/4] fix: correct error in `add` subcommand when target directory for repository relocation does not exist --- src/cmd/add.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cmd/add.rs b/src/cmd/add.rs index 6ec5ac0..2a463b2 100644 --- a/src/cmd/add.rs +++ b/src/cmd/add.rs @@ -1,7 +1,7 @@ -use std::fs::rename; +use std::fs::{create_dir_all, rename}; use std::path::PathBuf; -use anyhow::{bail, Result}; +use anyhow::{anyhow, bail, Result}; use clap::Parser; use console::style; use dialoguer::Confirm; @@ -80,6 +80,20 @@ impl Cmd { return Ok(()); } + let parent_path = path + .parent() + .ok_or_else(|| { + anyhow!( + "Failed to determine parent path for the repository's new location: {}", + path.to_string_lossy() + ) + })? + .to_path_buf(); + + if !parent_path.as_path().is_dir() { + create_dir_all(&parent_path)? + } + rename(&self.repo, &path)?; info!( "Added the repository successfully to: {}", From 163a06c86355a0c583bcc964103ed82c5b752a0b Mon Sep 17 00:00:00 2001 From: Tomoaki Ichige Date: Sat, 22 Jul 2023 06:10:40 +0900 Subject: [PATCH 2/4] fix: resolve problem with config file reference when applying profile in `add` subcommand --- src/cmd/add.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cmd/add.rs b/src/cmd/add.rs index 2a463b2..950bb17 100644 --- a/src/cmd/add.rs +++ b/src/cmd/add.rs @@ -100,6 +100,8 @@ impl Cmd { path.to_string_lossy(), ); + let repo = Repository::open(&path)?; + if let Some((name, p)) = profile { p.apply(&mut repo.config()?)?; From 08db4a9be6fd9c58b44ac5f99dc0541f8253611a Mon Sep 17 00:00:00 2001 From: Tomoaki Ichige Date: Sat, 22 Jul 2023 18:29:10 +0900 Subject: [PATCH 3/4] refactor: remove process to check if parent directory already exists before creation --- src/cmd/add.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cmd/add.rs b/src/cmd/add.rs index 950bb17..e736b44 100644 --- a/src/cmd/add.rs +++ b/src/cmd/add.rs @@ -90,9 +90,7 @@ impl Cmd { })? .to_path_buf(); - if !parent_path.as_path().is_dir() { - create_dir_all(&parent_path)? - } + create_dir_all(&parent_path)?; rename(&self.repo, &path)?; info!( From 475c308b98d9f5c7cede6e462ebf90e141ba2d88 Mon Sep 17 00:00:00 2001 From: Tomoaki Ichige Date: Sat, 22 Jul 2023 18:57:34 +0900 Subject: [PATCH 4/4] refactor: fix clippy warning --- src/cmd/add.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/add.rs b/src/cmd/add.rs index e736b44..794882f 100644 --- a/src/cmd/add.rs +++ b/src/cmd/add.rs @@ -90,7 +90,7 @@ impl Cmd { })? .to_path_buf(); - create_dir_all(&parent_path)?; + create_dir_all(parent_path)?; rename(&self.repo, &path)?; info!(