diff --git a/asyncgit/src/sync/commits_info.rs b/asyncgit/src/sync/commits_info.rs index 950dba07..d8f5ea3c 100644 --- a/asyncgit/src/sync/commits_info.rs +++ b/asyncgit/src/sync/commits_info.rs @@ -84,10 +84,10 @@ mod tests { File::create(&root.join(file_path))?.write_all(b"a")?; stage_add_file(repo_path, file_path); - let c1 = commit(repo_path, "commit1"); + let c1 = commit(repo_path, "commit1").unwrap(); File::create(&root.join(file_path))?.write_all(b"a")?; stage_add_file(repo_path, file_path); - let c2 = commit(repo_path, "commit2"); + let c2 = commit(repo_path, "commit2").unwrap(); let res = get_commits_info(repo_path, &vec![c2, c1]).unwrap(); diff --git a/asyncgit/src/sync/logwalker.rs b/asyncgit/src/sync/logwalker.rs index 249c7557..cd7c61b5 100644 --- a/asyncgit/src/sync/logwalker.rs +++ b/asyncgit/src/sync/logwalker.rs @@ -68,10 +68,10 @@ mod tests { File::create(&root.join(file_path))?.write_all(b"a")?; stage_add_file(repo_path, file_path); - commit(repo_path, "commit1"); + commit(repo_path, "commit1").unwrap(); File::create(&root.join(file_path))?.write_all(b"a")?; stage_add_file(repo_path, file_path); - let oid2 = commit(repo_path, "commit2"); + let oid2 = commit(repo_path, "commit2").unwrap(); let mut items = Vec::new(); let mut walk = LogWalker::new(&repo); @@ -92,10 +92,10 @@ mod tests { File::create(&root.join(file_path))?.write_all(b"a")?; stage_add_file(repo_path, file_path); - commit(repo_path, "commit1"); + commit(repo_path, "commit1").unwrap(); File::create(&root.join(file_path))?.write_all(b"a")?; stage_add_file(repo_path, file_path); - let oid2 = commit(repo_path, "commit2"); + let oid2 = commit(repo_path, "commit2").unwrap(); let mut items = Vec::new(); let mut walk = LogWalker::new(&repo); diff --git a/asyncgit/src/sync/reset.rs b/asyncgit/src/sync/reset.rs index 4c92867b..11dfcf64 100644 --- a/asyncgit/src/sync/reset.rs +++ b/asyncgit/src/sync/reset.rs @@ -207,7 +207,7 @@ mod tests { } assert!(stage_add_all(repo_path, "*")); - commit(repo_path, "msg"); + commit(repo_path, "msg").unwrap(); { File::create(&root.join("foo/file1.txt"))? diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index bf6da315..00989018 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -1,6 +1,8 @@ //! sync git api (various methods) -use git2::{IndexAddOption, Oid, Repository, RepositoryOpenFlags}; +use git2::{ + Error, IndexAddOption, Oid, Repository, RepositoryOpenFlags, +}; use scopetime::scope_time; use std::path::Path; @@ -31,19 +33,18 @@ pub fn repo(repo_path: &str) -> Repository { } /// this does not run any git hooks -pub fn commit(repo_path: &str, msg: &str) -> Oid { +pub fn commit(repo_path: &str, msg: &str) -> Result { scope_time!("commit"); let repo = repo(repo_path); - let signature = repo.signature().unwrap(); - let mut index = repo.index().unwrap(); - let tree_id = index.write_tree().unwrap(); - let tree = repo.find_tree(tree_id).unwrap(); + let signature = repo.signature()?; + let mut index = repo.index()?; + let tree_id = index.write_tree()?; + let tree = repo.find_tree(tree_id)?; let parents = if let Ok(reference) = repo.head() { - let parent = - repo.find_commit(reference.target().unwrap()).unwrap(); + let parent = repo.find_commit(reference.target().unwrap())?; vec![parent] } else { Vec::new() @@ -59,7 +60,6 @@ pub fn commit(repo_path: &str, msg: &str) -> Oid { &tree, parents.as_slice(), ) - .unwrap() } /// add a file diff from workingdir to stage (will not add removed files see `stage_addremoved`) @@ -144,7 +144,7 @@ mod tests { assert_eq!(get_statuses(repo_path), (0, 1)); - commit(repo_path, "commit msg"); + commit(repo_path, "commit msg").unwrap(); assert_eq!(get_statuses(repo_path), (0, 0)); } @@ -169,7 +169,7 @@ mod tests { assert_eq!(get_statuses(repo_path), (0, 1)); - commit(repo_path, "commit msg"); + commit(repo_path, "commit msg").unwrap(); assert_eq!(get_statuses(repo_path), (0, 0)); } @@ -256,7 +256,7 @@ mod tests { assert_eq!(stage_add_file(repo_path, file_path), true); - commit(repo_path, "commit msg"); + commit(repo_path, "commit msg").unwrap(); // delete the file now assert_eq!(remove_file(full_path).is_ok(), true); diff --git a/src/components/commit.rs b/src/components/commit.rs index 046dd3b4..8b141661 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -134,7 +134,7 @@ impl CommitComponent { return; } - sync::commit(CWD, &self.msg); + sync::commit(CWD, &self.msg).unwrap(); if let HookResult::NotOk(e) = sync::hooks_post_commit(CWD) { error!("post-commit hook error: {}", e); self.queue.borrow_mut().push_back(