mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
commit error handling
This commit is contained in:
parent
322800036d
commit
871f2cf2c3
5 changed files with 20 additions and 20 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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"))?
|
||||
|
|
|
|||
|
|
@ -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<Oid, Error> {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue