Run cargo fmt with new cargo version
This commit is contained in:
@@ -139,9 +139,10 @@ fn main() {
|
|||||||
Some(branch) => {
|
Some(branch) => {
|
||||||
let split = branch.split_once('/');
|
let split = branch.split_once('/');
|
||||||
|
|
||||||
if split.is_none() ||
|
if split.is_none()
|
||||||
split.unwrap().0.len() == 0
|
|| split.unwrap().0.len() == 0
|
||||||
||split.unwrap().1.len() == 0 {
|
|| split.unwrap().1.len() == 0
|
||||||
|
{
|
||||||
print_error("Tracking branch needs to match the pattern <remote>/<branch_name>");
|
print_error("Tracking branch needs to match the pattern <remote>/<branch_name>");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
};
|
};
|
||||||
@@ -256,7 +257,7 @@ fn main() {
|
|||||||
for warning in warnings {
|
for warning in warnings {
|
||||||
print_warning(&warning);
|
print_warning(&warning);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
print_error(&format!("Worktree cleanup failed: {}", error));
|
print_error(&format!("Worktree cleanup failed: {}", error));
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
|
|||||||
44
src/lib.rs
44
src/lib.rs
@@ -14,7 +14,7 @@ use output::*;
|
|||||||
|
|
||||||
use repo::{clone_repo, detect_remote_type, Remote, RepoConfig};
|
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 GIT_MAIN_WORKTREE_DIRECTORY: &str = ".git-main-working-tree";
|
||||||
const BRANCH_NAMESPACE_SEPARATOR: &str = "/";
|
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));
|
return Err(format!("Repository failed during setting of the remote URL for remote \"{}\": {}", &remote.name, e));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
print_repo_action(
|
print_repo_action(
|
||||||
&repo.name,
|
&repo.name,
|
||||||
@@ -345,14 +345,18 @@ fn find_repos(root: &Path) -> Result<Option<(Vec<RepoConfig>, Vec<String>, bool)
|
|||||||
},
|
},
|
||||||
error
|
error
|
||||||
));
|
));
|
||||||
continue
|
continue;
|
||||||
},
|
}
|
||||||
Ok(repo) => {
|
Ok(repo) => {
|
||||||
let remotes = match repo.remotes() {
|
let remotes = match repo.remotes() {
|
||||||
Ok(remote) => remote,
|
Ok(remote) => remote,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
warnings.push(format!("{}: Error getting remotes: {}", &path_as_string(&path), error));
|
warnings.push(format!(
|
||||||
continue
|
"{}: 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) {
|
let remote_type = match detect_remote_type(&url) {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => {
|
None => {
|
||||||
warnings.push(format!("{}: Could not detect remote type of \"{}\"", &path_as_string(&path), &url));
|
warnings.push(format!(
|
||||||
continue
|
"{}: 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 => {
|
None => {
|
||||||
warnings.push(format!("{}: Remote {} not found", &path_as_string(&path), remote_name));
|
warnings.push(format!(
|
||||||
continue
|
"{}: 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)))
|
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());
|
root = Path::new("~").join(root.strip_prefix(&home).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((Tree {
|
Ok((
|
||||||
root: root.into_os_string().into_string().unwrap(),
|
Tree {
|
||||||
repos: Some(repos),
|
root: root.into_os_string().into_string().unwrap(),
|
||||||
}, warnings))
|
repos: Some(repos),
|
||||||
|
},
|
||||||
|
warnings,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_worktree(
|
pub fn add_worktree(
|
||||||
|
|||||||
32
src/repo.rs
32
src/repo.rs
@@ -19,7 +19,7 @@ pub enum WorktreeRemoveFailureReason {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum GitPushDefaultSetting {
|
pub enum GitPushDefaultSetting {
|
||||||
Upstream
|
Upstream,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@@ -327,10 +327,17 @@ impl Repo {
|
|||||||
Ok(())
|
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(
|
Ok(Branch(
|
||||||
self.0
|
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)?,
|
.map_err(convert_libgit2_error)?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -408,9 +415,12 @@ impl Repo {
|
|||||||
let mut config = self.config()?;
|
let mut config = self.config()?;
|
||||||
|
|
||||||
config
|
config
|
||||||
.set_str(crate::GIT_CONFIG_PUSH_DEFAULT, match value {
|
.set_str(
|
||||||
GitPushDefaultSetting::Upstream => "upstream",
|
crate::GIT_CONFIG_PUSH_DEFAULT,
|
||||||
})
|
match value {
|
||||||
|
GitPushDefaultSetting::Upstream => "upstream",
|
||||||
|
},
|
||||||
|
)
|
||||||
.map_err(|error| {
|
.map_err(|error| {
|
||||||
format!(
|
format!(
|
||||||
"Could not set {}: {}",
|
"Could not set {}: {}",
|
||||||
@@ -602,8 +612,11 @@ impl Repo {
|
|||||||
pub fn find_remote(&self, remote_name: &str) -> Result<Option<RemoteHandle>, String> {
|
pub fn find_remote(&self, remote_name: &str) -> Result<Option<RemoteHandle>, String> {
|
||||||
let remotes = self.0.remotes().map_err(convert_libgit2_error)?;
|
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) {
|
if !remotes
|
||||||
return Ok(None)
|
.iter()
|
||||||
|
.any(|remote| remote.expect("Remote name is invalid utf-8") == remote_name)
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(RemoteHandle(
|
Ok(Some(RemoteHandle(
|
||||||
@@ -760,7 +773,8 @@ impl Repo {
|
|||||||
let mut unmanaged_worktrees = Vec::new();
|
let mut unmanaged_worktrees = Vec::new();
|
||||||
for entry in std::fs::read_dir(&directory).map_err(|error| error.to_string())? {
|
for entry in std::fs::read_dir(&directory).map_err(|error| error.to_string())? {
|
||||||
let dirname = crate::path_as_string(
|
let dirname = crate::path_as_string(
|
||||||
&entry.map_err(|error| error.to_string())?
|
&entry
|
||||||
|
.map_err(|error| error.to_string())?
|
||||||
.path()
|
.path()
|
||||||
.strip_prefix(&directory)
|
.strip_prefix(&directory)
|
||||||
// that unwrap() is safe as each entry is
|
// 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(())
|
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 table = Table::new();
|
||||||
let mut warnings = Vec::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() {
|
let repo_name = match path.file_name() {
|
||||||
None => {
|
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")
|
String::from("unknown")
|
||||||
}
|
}
|
||||||
Some(file_name) => match file_name.to_str() {
|
Some(file_name) => match file_name.to_str() {
|
||||||
None => {
|
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")
|
String::from("invalid")
|
||||||
}
|
}
|
||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user