Run cargo fmt with new cargo version
This commit is contained in:
@@ -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 <remote>/<branch_name>");
|
||||
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);
|
||||
|
||||
40
src/lib.rs
40
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<Option<(Vec<RepoConfig>, Vec<String>, 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<Option<(Vec<RepoConfig>, Vec<String>, 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<Option<(Vec<RepoConfig>, Vec<String>, 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<Option<(Vec<RepoConfig>, Vec<String>, bool)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Ok(Some((repos, warnings, repo_in_root)))
|
||||
}
|
||||
@@ -437,10 +448,13 @@ pub fn find_in_tree(path: &Path) -> Result<(Tree, Vec<String>), String> {
|
||||
root = Path::new("~").join(root.strip_prefix(&home).unwrap());
|
||||
}
|
||||
|
||||
Ok((Tree {
|
||||
Ok((
|
||||
Tree {
|
||||
root: root.into_os_string().into_string().unwrap(),
|
||||
repos: Some(repos),
|
||||
}, warnings))
|
||||
},
|
||||
warnings,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn add_worktree(
|
||||
|
||||
30
src/repo.rs
30
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<Branch, String> {
|
||||
pub fn find_remote_branch(
|
||||
&self,
|
||||
remote_name: &str,
|
||||
branch_name: &str,
|
||||
) -> Result<Branch, String> {
|
||||
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 {
|
||||
.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<Option<RemoteHandle>, 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
|
||||
|
||||
14
src/table.rs
14
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>), String> {
|
||||
pub fn show_single_repo_status(
|
||||
path: &Path,
|
||||
) -> Result<(impl std::fmt::Display, Vec<String>), 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(),
|
||||
|
||||
Reference in New Issue
Block a user