cleanup some result return types

This commit is contained in:
Stephan Dilly 2020-05-15 18:23:07 +02:00
parent 11f78a4091
commit f8294dcb7b
4 changed files with 26 additions and 61 deletions

View file

@ -313,10 +313,7 @@ mod tests {
assert_eq!(get_statuses(repo_path), (1, 0)); assert_eq!(get_statuses(repo_path), (1, 0));
assert_eq!( stage_add_file(repo_path, file_path).unwrap();
stage_add_file(repo_path, file_path).unwrap(),
true
);
assert_eq!(get_statuses(repo_path), (0, 1)); assert_eq!(get_statuses(repo_path), (0, 1));
@ -378,9 +375,7 @@ mod tests {
assert_eq!(res.len(), 1); assert_eq!(res.len(), 1);
assert_eq!(res[0].path, "bar.txt"); assert_eq!(res[0].path, "bar.txt");
let res = stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
stage_add_file(repo_path, Path::new("bar.txt")).unwrap();
assert_eq!(res, true);
assert_eq!(get_statuses(repo_path), (0, 1)); assert_eq!(get_statuses(repo_path), (0, 1));
// overwrite with next content // overwrite with next content

View file

@ -213,7 +213,7 @@ mod tests {
.write_all(b"file3")?; .write_all(b"file3")?;
} }
assert!(stage_add_all(repo_path, "*").unwrap()); stage_add_all(repo_path, "*").unwrap();
commit(repo_path, "msg").unwrap(); commit(repo_path, "msg").unwrap();
{ {
@ -295,10 +295,7 @@ mod tests {
assert_eq!(get_statuses(repo_path), (1, 0)); assert_eq!(get_statuses(repo_path), (1, 0));
assert_eq!( stage_add_file(repo_path, file_path).unwrap();
stage_add_file(repo_path, file_path).unwrap(),
true
);
assert_eq!(get_statuses(repo_path), (0, 1)); assert_eq!(get_statuses(repo_path), (0, 1));

View file

@ -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`) /// 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"); scope_time!("stage_add_file");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let mut index = repo.index()?; let mut index = repo.index()?;
if index.add_path(path).is_ok() { index.add_path(path)?;
index.write()?; index.write()?;
return Ok(true);
}
Ok(false) Ok(())
} }
/// like `stage_add_file` but uses a pattern to match/glob multiple files/folders /// 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"); scope_time!("stage_add_all");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let mut index = repo.index()?; let mut index = repo.index()?;
if index index.add_all(vec![pattern], IndexAddOption::DEFAULT, None)?;
.add_all(vec![pattern], IndexAddOption::DEFAULT, None) index.write()?;
.is_ok()
{
index.write()?;
return Ok(true);
}
Ok(false) Ok(())
} }
/// stage a removed file /// stage a removed file
pub fn stage_addremoved( pub fn stage_addremoved(repo_path: &str, path: &Path) -> Result<()> {
repo_path: &str,
path: &Path,
) -> Result<bool> {
scope_time!("stage_addremoved"); scope_time!("stage_addremoved");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let mut index = repo.index()?; let mut index = repo.index()?;
if index.remove_path(path).is_ok() { index.remove_path(path)?;
index.write()?; index.write()?;
return Ok(true);
}
Ok(false) Ok(())
} }
#[cfg(test)] #[cfg(test)]
@ -148,10 +136,7 @@ mod tests {
assert_eq!(get_statuses(repo_path), (1, 0)); assert_eq!(get_statuses(repo_path), (1, 0));
assert_eq!( stage_add_file(repo_path, file_path).unwrap();
stage_add_file(repo_path, file_path).unwrap(),
true
);
assert_eq!(get_statuses(repo_path), (0, 1)); assert_eq!(get_statuses(repo_path), (0, 1));
@ -176,10 +161,7 @@ mod tests {
assert_eq!(get_statuses(repo_path), (1, 0)); assert_eq!(get_statuses(repo_path), (1, 0));
assert_eq!( stage_add_file(repo_path, file_path).unwrap();
stage_add_file(repo_path, file_path).unwrap(),
true
);
assert_eq!(get_statuses(repo_path), (0, 1)); assert_eq!(get_statuses(repo_path), (0, 1));
@ -196,7 +178,7 @@ mod tests {
let repo_path = root.as_os_str().to_str().unwrap(); let repo_path = root.as_os_str().to_str().unwrap();
assert_eq!( assert_eq!(
stage_add_file(repo_path, file_path).unwrap(), stage_add_file(repo_path, file_path).is_ok(),
false false
); );
} }
@ -220,10 +202,7 @@ mod tests {
assert_eq!(get_statuses(repo_path), (2, 0)); assert_eq!(get_statuses(repo_path), (2, 0));
assert_eq!( stage_add_file(repo_path, file_path).unwrap();
stage_add_file(repo_path, file_path).unwrap(),
true
);
assert_eq!(get_statuses(repo_path), (1, 1)); assert_eq!(get_statuses(repo_path), (1, 1));
} }
@ -248,7 +227,7 @@ mod tests {
assert_eq!(status_count(StatusType::WorkingDir), 3); 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::WorkingDir), 1);
assert_eq!(status_count(StatusType::Stage), 2); assert_eq!(status_count(StatusType::Stage), 2);
@ -274,10 +253,7 @@ mod tests {
.write_all(b"test file1 content") .write_all(b"test file1 content")
.unwrap(); .unwrap();
assert_eq!( stage_add_file(repo_path, file_path).unwrap();
stage_add_file(repo_path, file_path).unwrap(),
true
);
commit(repo_path, "commit msg").unwrap(); commit(repo_path, "commit msg").unwrap();
@ -287,10 +263,7 @@ mod tests {
// deleted file in diff now // deleted file in diff now
assert_eq!(status_count(StatusType::WorkingDir), 1); assert_eq!(status_count(StatusType::WorkingDir), 1);
assert_eq!( stage_addremoved(repo_path, file_path).unwrap();
stage_addremoved(repo_path, file_path).unwrap(),
true
);
assert_eq!(status_count(StatusType::WorkingDir), 0); assert_eq!(status_count(StatusType::WorkingDir), 0);
assert_eq!(status_count(StatusType::Stage), 1); assert_eq!(status_count(StatusType::Stage), 1);

View file

@ -109,10 +109,10 @@ impl ChangesComponent {
return match status { return match status {
StatusItemType::Deleted => { StatusItemType::Deleted => {
sync::stage_addremoved(CWD, path) sync::stage_addremoved(CWD, path)
.unwrap() .is_ok()
} }
_ => sync::stage_add_file(CWD, path) _ => sync::stage_add_file(CWD, path)
.unwrap(), .is_ok(),
}; };
} }
} else { } else {
@ -121,7 +121,7 @@ impl ChangesComponent {
CWD, CWD,
tree_item.info.full_path.as_str(), tree_item.info.full_path.as_str(),
) )
.unwrap(); .is_ok();
} }
} else { } else {
let path = let path =