mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
cleanup some result return types
This commit is contained in:
parent
11f78a4091
commit
f8294dcb7b
4 changed files with 26 additions and 61 deletions
|
|
@ -313,10 +313,7 @@ mod tests {
|
|||
|
||||
assert_eq!(get_statuses(repo_path), (1, 0));
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
|
||||
assert_eq!(get_statuses(repo_path), (0, 1));
|
||||
|
||||
|
|
@ -378,9 +375,7 @@ mod tests {
|
|||
assert_eq!(res.len(), 1);
|
||||
assert_eq!(res[0].path, "bar.txt");
|
||||
|
||||
let res =
|
||||
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
|
||||
assert_eq!(res, true);
|
||||
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
|
||||
assert_eq!(get_statuses(repo_path), (0, 1));
|
||||
|
||||
// overwrite with next content
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ mod tests {
|
|||
.write_all(b"file3")?;
|
||||
}
|
||||
|
||||
assert!(stage_add_all(repo_path, "*").unwrap());
|
||||
stage_add_all(repo_path, "*").unwrap();
|
||||
commit(repo_path, "msg").unwrap();
|
||||
|
||||
{
|
||||
|
|
@ -295,10 +295,7 @@ mod tests {
|
|||
|
||||
assert_eq!(get_statuses(repo_path), (1, 0));
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
|
||||
assert_eq!(get_statuses(repo_path), (0, 1));
|
||||
|
||||
|
|
|
|||
|
|
@ -68,57 +68,45 @@ pub fn commit(repo_path: &str, msg: &str) -> Result<Oid> {
|
|||
}
|
||||
|
||||
/// add a file diff from workingdir to stage (will not add removed files see `stage_addremoved`)
|
||||
pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<bool> {
|
||||
pub fn stage_add_file(repo_path: &str, path: &Path) -> Result<()> {
|
||||
scope_time!("stage_add_file");
|
||||
|
||||
let repo = repo(repo_path)?;
|
||||
|
||||
let mut index = repo.index()?;
|
||||
|
||||
if index.add_path(path).is_ok() {
|
||||
index.write()?;
|
||||
return Ok(true);
|
||||
}
|
||||
index.add_path(path)?;
|
||||
index.write()?;
|
||||
|
||||
Ok(false)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// like `stage_add_file` but uses a pattern to match/glob multiple files/folders
|
||||
pub fn stage_add_all(repo_path: &str, pattern: &str) -> Result<bool> {
|
||||
pub fn stage_add_all(repo_path: &str, pattern: &str) -> Result<()> {
|
||||
scope_time!("stage_add_all");
|
||||
|
||||
let repo = repo(repo_path)?;
|
||||
|
||||
let mut index = repo.index()?;
|
||||
|
||||
if index
|
||||
.add_all(vec![pattern], IndexAddOption::DEFAULT, None)
|
||||
.is_ok()
|
||||
{
|
||||
index.write()?;
|
||||
return Ok(true);
|
||||
}
|
||||
index.add_all(vec![pattern], IndexAddOption::DEFAULT, None)?;
|
||||
index.write()?;
|
||||
|
||||
Ok(false)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// stage a removed file
|
||||
pub fn stage_addremoved(
|
||||
repo_path: &str,
|
||||
path: &Path,
|
||||
) -> Result<bool> {
|
||||
pub fn stage_addremoved(repo_path: &str, path: &Path) -> Result<()> {
|
||||
scope_time!("stage_addremoved");
|
||||
|
||||
let repo = repo(repo_path)?;
|
||||
|
||||
let mut index = repo.index()?;
|
||||
|
||||
if index.remove_path(path).is_ok() {
|
||||
index.write()?;
|
||||
return Ok(true);
|
||||
}
|
||||
index.remove_path(path)?;
|
||||
index.write()?;
|
||||
|
||||
Ok(false)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -148,10 +136,7 @@ mod tests {
|
|||
|
||||
assert_eq!(get_statuses(repo_path), (1, 0));
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
|
||||
assert_eq!(get_statuses(repo_path), (0, 1));
|
||||
|
||||
|
|
@ -176,10 +161,7 @@ mod tests {
|
|||
|
||||
assert_eq!(get_statuses(repo_path), (1, 0));
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
|
||||
assert_eq!(get_statuses(repo_path), (0, 1));
|
||||
|
||||
|
|
@ -196,7 +178,7 @@ mod tests {
|
|||
let repo_path = root.as_os_str().to_str().unwrap();
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
stage_add_file(repo_path, file_path).is_ok(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
|
@ -220,10 +202,7 @@ mod tests {
|
|||
|
||||
assert_eq!(get_statuses(repo_path), (2, 0));
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
|
||||
assert_eq!(get_statuses(repo_path), (1, 1));
|
||||
}
|
||||
|
|
@ -248,7 +227,7 @@ mod tests {
|
|||
|
||||
assert_eq!(status_count(StatusType::WorkingDir), 3);
|
||||
|
||||
assert_eq!(stage_add_all(repo_path, "a/d").unwrap(), true);
|
||||
stage_add_all(repo_path, "a/d").unwrap();
|
||||
|
||||
assert_eq!(status_count(StatusType::WorkingDir), 1);
|
||||
assert_eq!(status_count(StatusType::Stage), 2);
|
||||
|
|
@ -274,10 +253,7 @@ mod tests {
|
|||
.write_all(b"test file1 content")
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
stage_add_file(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
|
||||
commit(repo_path, "commit msg").unwrap();
|
||||
|
||||
|
|
@ -287,10 +263,7 @@ mod tests {
|
|||
// deleted file in diff now
|
||||
assert_eq!(status_count(StatusType::WorkingDir), 1);
|
||||
|
||||
assert_eq!(
|
||||
stage_addremoved(repo_path, file_path).unwrap(),
|
||||
true
|
||||
);
|
||||
stage_addremoved(repo_path, file_path).unwrap();
|
||||
|
||||
assert_eq!(status_count(StatusType::WorkingDir), 0);
|
||||
assert_eq!(status_count(StatusType::Stage), 1);
|
||||
|
|
|
|||
|
|
@ -109,10 +109,10 @@ impl ChangesComponent {
|
|||
return match status {
|
||||
StatusItemType::Deleted => {
|
||||
sync::stage_addremoved(CWD, path)
|
||||
.unwrap()
|
||||
.is_ok()
|
||||
}
|
||||
_ => sync::stage_add_file(CWD, path)
|
||||
.unwrap(),
|
||||
.is_ok(),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
|
|
@ -121,7 +121,7 @@ impl ChangesComponent {
|
|||
CWD,
|
||||
tree_item.info.full_path.as_str(),
|
||||
)
|
||||
.unwrap();
|
||||
.is_ok();
|
||||
}
|
||||
} else {
|
||||
let path =
|
||||
|
|
|
|||
Loading…
Reference in a new issue