From 0b181b9b7914115e890d373130acc58d8ce45cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Tue, 21 Dec 2021 16:15:12 +0100 Subject: [PATCH] Run cargo fmt with new cargo version --- src/grm/main.rs | 9 +++++---- src/lib.rs | 44 +++++++++++++++++++++++++++++--------------- src/repo.rs | 32 +++++++++++++++++++++++--------- src/table.rs | 14 +++++++++++--- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/grm/main.rs b/src/grm/main.rs index b021a80..046eb89 100644 --- a/src/grm/main.rs +++ b/src/grm/main.rs @@ -139,9 +139,10 @@ fn main() { Some(branch) => { let split = branch.split_once('/'); - if split.is_none() || - split.unwrap().0.len() == 0 - ||split.unwrap().1.len() == 0 { + if split.is_none() + || split.unwrap().0.len() == 0 + || split.unwrap().1.len() == 0 + { print_error("Tracking branch needs to match the pattern /"); process::exit(1); }; @@ -256,7 +257,7 @@ fn main() { for warning in warnings { print_warning(&warning); } - }, + } Err(error) => { print_error(&format!("Worktree cleanup failed: {}", error)); process::exit(1); diff --git a/src/lib.rs b/src/lib.rs index 36d7898..fded766 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ use output::*; use repo::{clone_repo, detect_remote_type, Remote, RepoConfig}; -pub use repo::{RemoteTrackingStatus, RepoErrorKind, Repo, WorktreeRemoveFailureReason}; +pub use repo::{RemoteTrackingStatus, Repo, RepoErrorKind, WorktreeRemoveFailureReason}; const GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree"; const BRANCH_NAMESPACE_SEPARATOR: &str = "/"; @@ -177,7 +177,7 @@ fn sync_repo(root_path: &Path, repo: &RepoConfig) -> Result<(), String> { return Err(format!("Repository failed during setting of the remote URL for remote \"{}\": {}", &remote.name, e)); }; } - }, + } None => { print_repo_action( &repo.name, @@ -345,14 +345,18 @@ fn find_repos(root: &Path) -> Result, Vec, bool) }, error )); - continue - }, + continue; + } Ok(repo) => { let remotes = match repo.remotes() { Ok(remote) => remote, Err(error) => { - warnings.push(format!("{}: Error getting remotes: {}", &path_as_string(&path), error)); - continue + warnings.push(format!( + "{}: Error getting remotes: {}", + &path_as_string(&path), + error + )); + continue; } }; @@ -365,8 +369,12 @@ fn find_repos(root: &Path) -> Result, Vec, bool) let remote_type = match detect_remote_type(&url) { Some(t) => t, None => { - warnings.push(format!("{}: Could not detect remote type of \"{}\"", &path_as_string(&path), &url)); - continue + warnings.push(format!( + "{}: Could not detect remote type of \"{}\"", + &path_as_string(&path), + &url + )); + continue; } }; @@ -377,8 +385,12 @@ fn find_repos(root: &Path) -> Result, Vec, bool) }); } None => { - warnings.push(format!("{}: Remote {} not found", &path_as_string(&path), remote_name)); - continue + warnings.push(format!( + "{}: Remote {} not found", + &path_as_string(&path), + remote_name + )); + continue; } }; } @@ -400,7 +412,6 @@ fn find_repos(root: &Path) -> Result, Vec, bool) }); } } - } Ok(Some((repos, warnings, repo_in_root))) } @@ -437,10 +448,13 @@ pub fn find_in_tree(path: &Path) -> Result<(Tree, Vec), String> { root = Path::new("~").join(root.strip_prefix(&home).unwrap()); } - Ok((Tree { - root: root.into_os_string().into_string().unwrap(), - repos: Some(repos), - }, warnings)) + Ok(( + Tree { + root: root.into_os_string().into_string().unwrap(), + repos: Some(repos), + }, + warnings, + )) } pub fn add_worktree( diff --git a/src/repo.rs b/src/repo.rs index e127f7e..945aab9 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -19,7 +19,7 @@ pub enum WorktreeRemoveFailureReason { } pub enum GitPushDefaultSetting { - Upstream + Upstream, } #[derive(Debug, PartialEq)] @@ -327,10 +327,17 @@ impl Repo { Ok(()) } - pub fn find_remote_branch(&self, remote_name: &str, branch_name: &str) -> Result { + pub fn find_remote_branch( + &self, + remote_name: &str, + branch_name: &str, + ) -> Result { Ok(Branch( self.0 - .find_branch(&format!("{}/{}", remote_name, branch_name), git2::BranchType::Remote) + .find_branch( + &format!("{}/{}", remote_name, branch_name), + git2::BranchType::Remote, + ) .map_err(convert_libgit2_error)?, )) } @@ -408,9 +415,12 @@ impl Repo { let mut config = self.config()?; config - .set_str(crate::GIT_CONFIG_PUSH_DEFAULT, match value { - GitPushDefaultSetting::Upstream => "upstream", - }) + .set_str( + crate::GIT_CONFIG_PUSH_DEFAULT, + match value { + GitPushDefaultSetting::Upstream => "upstream", + }, + ) .map_err(|error| { format!( "Could not set {}: {}", @@ -602,8 +612,11 @@ impl Repo { pub fn find_remote(&self, remote_name: &str) -> Result, String> { let remotes = self.0.remotes().map_err(convert_libgit2_error)?; - if !remotes.iter().any(|remote| remote.expect("Remote name is invalid utf-8") == remote_name) { - return Ok(None) + if !remotes + .iter() + .any(|remote| remote.expect("Remote name is invalid utf-8") == remote_name) + { + return Ok(None); } Ok(Some(RemoteHandle( @@ -760,7 +773,8 @@ impl Repo { let mut unmanaged_worktrees = Vec::new(); for entry in std::fs::read_dir(&directory).map_err(|error| error.to_string())? { let dirname = crate::path_as_string( - &entry.map_err(|error| error.to_string())? + &entry + .map_err(|error| error.to_string())? .path() .strip_prefix(&directory) // that unwrap() is safe as each entry is diff --git a/src/table.rs b/src/table.rs index 9b94c5e..8091725 100644 --- a/src/table.rs +++ b/src/table.rs @@ -274,7 +274,9 @@ fn add_worktree_status( Ok(()) } -pub fn show_single_repo_status(path: &Path) -> Result<(impl std::fmt::Display, Vec), String> { +pub fn show_single_repo_status( + path: &Path, +) -> Result<(impl std::fmt::Display, Vec), String> { let mut table = Table::new(); let mut warnings = Vec::new(); @@ -293,12 +295,18 @@ pub fn show_single_repo_status(path: &Path) -> Result<(impl std::fmt::Display, V let repo_name = match path.file_name() { None => { - warnings.push(format!("Cannot detect repo name for path {}. Are you working in /?", &path.display())); + warnings.push(format!( + "Cannot detect repo name for path {}. Are you working in /?", + &path.display() + )); String::from("unknown") } Some(file_name) => match file_name.to_str() { None => { - warnings.push(format!("Name of repo directory {} is not valid UTF-8", &path.display())); + warnings.push(format!( + "Name of repo directory {} is not valid UTF-8", + &path.display() + )); String::from("invalid") } Some(name) => name.to_string(),