summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-04-19 17:37:17 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-04-19 17:37:17 +0200
commitd2a49919a5b9c0593887fa26596959c7ce9db4b0 (patch)
treedd745e29f7558e9800cfd45809b7d0f4d39752ff
parent4598b482432ba628d91b4d1858dee4b7b5c85e7f (diff)
Took some suggestions from clippy
-rw-r--r--src/git.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/git.rs b/src/git.rs
index 3cfaa8c..d571386 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -3,7 +3,11 @@ use crate::{
ShackleError,
};
use git2::{ErrorCode, Repository, RepositoryInitMode, RepositoryInitOptions};
-use std::{fs, path::PathBuf, process::Command};
+use std::{
+ fs,
+ path::{Path, PathBuf},
+ process::Command,
+};
use user_info::{get_user_groups, get_username};
pub struct GitInitResult {
@@ -28,7 +32,7 @@ fn group_git_dir(group: &str) -> PathBuf {
git_dir_prefix().join(group)
}
-fn is_valid_git_repo_path(path: &PathBuf) -> Result<bool, ShackleError> {
+fn is_valid_git_repo_path(path: &Path) -> Result<bool, ShackleError> {
let prefix = git_dir_prefix();
let relative_path = match path.strip_prefix(&prefix) {
Ok(relative_path) => relative_path,
@@ -94,7 +98,7 @@ pub fn init(
if let Some(description) = description {
// There is an init option for setting the description but it seems to
// just do nothing?
- set_description(&path, &description)?;
+ set_description(&path, description)?;
}
Ok(GitInitResult { path })
@@ -107,7 +111,7 @@ pub struct RepoMetadata {
pub fn list() -> Result<Vec<RepoMetadata>, ShackleError> {
fn add_from_dir(
- collection_dir: &PathBuf,
+ collection_dir: &Path,
is_checking_group: bool,
) -> Result<Vec<RepoMetadata>, ShackleError> {
let mut results = Vec::new();
@@ -153,14 +157,14 @@ pub fn list() -> Result<Vec<RepoMetadata>, ShackleError> {
results.append(&mut add_from_dir(&personal_git_dir()?, false)?);
let groups = get_user_groups();
for group in &groups {
- results.append(&mut add_from_dir(&group_git_dir(&group), true)?);
+ results.append(&mut add_from_dir(&group_git_dir(group), true)?);
}
Ok(results)
}
-pub fn set_description(directory: &PathBuf, description: &str) -> Result<(), ShackleError> {
- if !is_valid_git_repo_path(&directory)? {
+pub fn set_description(directory: &Path, description: &str) -> Result<(), ShackleError> {
+ if !is_valid_git_repo_path(directory)? {
return Err(ShackleError::InvalidDirectory);
}
@@ -172,12 +176,12 @@ pub fn set_description(directory: &PathBuf, description: &str) -> Result<(), Sha
}
}
-pub fn set_branch(directory: &PathBuf, branch: &str) -> Result<(), ShackleError> {
- if !is_valid_git_repo_path(&directory)? {
+pub fn set_branch(directory: &Path, branch: &str) -> Result<(), ShackleError> {
+ if !is_valid_git_repo_path(directory)? {
return Err(ShackleError::InvalidDirectory);
}
- if let Ok(repo) = Repository::open_bare(&directory) {
+ if let Ok(repo) = Repository::open_bare(directory) {
repo.reference_symbolic(
"HEAD",
&format!("refs/heads/{branch}"),