diff --git a/src-tauri/src/gb_repository/repository.rs b/src-tauri/src/gb_repository/repository.rs index ba38849d8..d309aaefe 100644 --- a/src-tauri/src/gb_repository/repository.rs +++ b/src-tauri/src/gb_repository/repository.rs @@ -547,7 +547,7 @@ impl Repository { // lookup a branch by name let branch = repo.find_branch(&target_branch, git2::BranchType::Remote)?; - let remote = repo.branch_remote_name(&branch.get().name().unwrap())?; + let remote = repo.branch_remote_name(branch.get().name().unwrap())?; let remote_url = repo.find_remote(remote.as_str().unwrap())?; let remote_url_str = remote_url.url().unwrap(); println!("remote: {}", remote_url_str); @@ -571,7 +571,7 @@ impl Repository { // if there are no applied virtual branches, calculate the sha as the merge-base between HEAD in project_repository and this target commit let commit = branch.get().peel_to_commit()?; let mut commit_oid = commit.id(); - if active_virtual_branches.len() == 0 { + if active_virtual_branches.is_empty() { // calculate the commit as the merge-base between HEAD in project_repository and this target commit let head_oid = repo .head() @@ -599,7 +599,7 @@ impl Repository { let branch_writer = virtual_branches::branch::Writer::new(self); - if active_virtual_branches.len() == 0 { + if active_virtual_branches.is_empty() { let now = time::UNIX_EPOCH.elapsed().unwrap().as_millis(); let branch = virtual_branches::branch::Branch { id: Uuid::new_v4().to_string(), diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0207b61ae..2b5080634 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -618,11 +618,10 @@ async fn move_virtual_branch_files( paths: Vec<&str>, ) -> Result<(), Error> { let app = handle.state::(); - let target = app - .move_virtual_branch_files(project_id, branch, paths) + app.move_virtual_branch_files(project_id, branch, paths) .await .context("failed to move virtual branch files")?; - Ok(target) + Ok(()) } #[timed(duration(printer = "debug!"))] @@ -634,8 +633,8 @@ async fn commit_virtual_branch( message: &str, ) -> Result<(), Error> { let app = handle.state::(); - let target = app.commit_virtual_branch(project_id, branch, message)?; - Ok(target) + app.commit_virtual_branch(project_id, branch, message)?; + Ok(()) } #[timed(duration(printer = "debug!"))] @@ -667,8 +666,8 @@ async fn set_target_branch( #[tauri::command(async)] async fn update_branch_target(handle: tauri::AppHandle, project_id: &str) -> Result<(), Error> { let app = handle.state::(); - let target = app.update_branch_target(project_id)?; - Ok(target) + app.update_branch_target(project_id)?; + Ok(()) } #[timed(duration(printer = "debug!"))] @@ -679,8 +678,8 @@ async fn apply_branch( branch: &str, ) -> Result<(), Error> { let app = handle.state::(); - let target = app.apply_virtual_branch(project_id, branch)?; - Ok(target) + app.apply_virtual_branch(project_id, branch)?; + Ok(()) } #[timed(duration(printer = "debug!"))] @@ -691,8 +690,8 @@ async fn unapply_branch( branch: &str, ) -> Result<(), Error> { let app = handle.state::(); - let target = app.unapply_virtual_branch(project_id, branch)?; - Ok(target) + app.unapply_virtual_branch(project_id, branch)?; + Ok(()) } fn main() { diff --git a/src-tauri/src/virtual_branches/branch/hunk.rs b/src-tauri/src/virtual_branches/branch/hunk.rs index 1fe03cb72..4decff6cc 100644 --- a/src-tauri/src/virtual_branches/branch/hunk.rs +++ b/src-tauri/src/virtual_branches/branch/hunk.rs @@ -60,10 +60,6 @@ impl Hunk { } } - pub fn start(&self) -> &usize { - &self.start - } - pub fn contains(&self, line: &usize) -> bool { self.start <= *line && self.end >= *line } diff --git a/src-tauri/src/virtual_branches/mod.rs b/src-tauri/src/virtual_branches/mod.rs index 15a62a0e8..466d1e575 100644 --- a/src-tauri/src/virtual_branches/mod.rs +++ b/src-tauri/src/virtual_branches/mod.rs @@ -124,7 +124,7 @@ pub fn apply_branch( let branch_tree = gb_repository .git_repository - .find_tree(target_branch.tree.clone()) + .find_tree(target_branch.tree) .context("failed to find branch tree")?; let merge_options = git2::MergeOptions::new(); @@ -410,13 +410,8 @@ pub fn list_virtual_branches( .into_iter() .find(|(vbranch, _)| vbranch.id == branch.id); - match maybe_status { - Some((_vbranch, sfiles)) => { - files = sfiles.clone(); - } - None => { - // this branch has no status, so we just skip it - } + if let Some((_vbranch, sfiles)) = maybe_status { + files = sfiles.clone(); } let mut vfiles = vec![]; @@ -911,7 +906,7 @@ pub fn get_status_by_branch( .filter(|b| b.applied) .any(|b| b.id == default_branch_id) { - default_branch_id = first_branch_id.clone().unwrap().clone(); + default_branch_id = first_branch_id.unwrap() } // now, distribute hunks to the branches @@ -1096,7 +1091,7 @@ pub fn update_branch_target( let vbranches = list_virtual_branches(gb_repository, project_repository)?; - let mut merge_options = git2::MergeOptions::new(); + let merge_options = git2::MergeOptions::new(); // get tree from new target let new_target_commit = repo.find_commit(new_target_oid)?; @@ -1251,7 +1246,7 @@ fn write_tree( // if file exists if full_path.exists() { // add file to index - index.add_path(&rel_path).unwrap(); + index.add_path(rel_path).unwrap(); } } @@ -1265,13 +1260,12 @@ fn _print_tree(repo: &git2::Repository, tree: &git2::Tree) { for entry in tree.iter() { println!("entry: {:?} {:?}", entry.name(), entry.id()); // get entry contents - let object = entry.to_object(&repo).unwrap(); + let object = entry.to_object(repo).unwrap(); let blob = object.as_blob().unwrap(); // convert content to string let content = std::str::from_utf8(blob.content()).unwrap(); println!("blob: {:?}", content); } - println!(""); } pub fn commit( @@ -2307,7 +2301,7 @@ mod tests { // there should be a new vbranch created, but nothing is on it let branches = list_virtual_branches(&gb_repo, &project_repository)?; let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); - assert_eq!(branch.active, false); + assert!(!branch.active); assert_eq!(branch.commits.len(), 1); Ok(()) @@ -2475,7 +2469,7 @@ mod tests { let branches = list_virtual_branches(&gb_repo, &project_repository)?; let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); assert_eq!(branch.files.len(), 1); - assert_eq!(branch.active, true); + assert!(branch.active); unapply_branch(&gb_repo, &project_repository, &branch1_id)?; @@ -2487,7 +2481,7 @@ mod tests { let branches = list_virtual_branches(&gb_repo, &project_repository)?; let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); assert_eq!(branch.files.len(), 0); - assert_eq!(branch.active, false); + assert!(!branch.active); apply_branch(&gb_repo, &project_repository, &branch1_id)?; let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path))?; @@ -2501,7 +2495,7 @@ mod tests { let branches = list_virtual_branches(&gb_repo, &project_repository)?; let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); assert_eq!(branch.files.len(), 1); - assert_eq!(branch.active, true); + assert!(branch.active); Ok(()) } diff --git a/src-tauri/src/watcher/handlers/check_current_session.rs b/src-tauri/src/watcher/handlers/check_current_session.rs index 765386a97..268947297 100644 --- a/src-tauri/src/watcher/handlers/check_current_session.rs +++ b/src-tauri/src/watcher/handlers/check_current_session.rs @@ -14,7 +14,7 @@ pub struct Handler { user_store: users::Storage, } -impl<'handler> Handler { +impl Handler { pub fn new( local_data_dir: path::PathBuf, project_id: String,