Skip to content

Commit 871f2cf

Browse files
author
Stephan Dilly
committed
commit error handling
1 parent 3228000 commit 871f2cf

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

asyncgit/src/sync/commits_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ mod tests {
8484

8585
File::create(&root.join(file_path))?.write_all(b"a")?;
8686
stage_add_file(repo_path, file_path);
87-
let c1 = commit(repo_path, "commit1");
87+
let c1 = commit(repo_path, "commit1").unwrap();
8888
File::create(&root.join(file_path))?.write_all(b"a")?;
8989
stage_add_file(repo_path, file_path);
90-
let c2 = commit(repo_path, "commit2");
90+
let c2 = commit(repo_path, "commit2").unwrap();
9191

9292
let res = get_commits_info(repo_path, &vec![c2, c1]).unwrap();
9393

asyncgit/src/sync/logwalker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ mod tests {
6868

6969
File::create(&root.join(file_path))?.write_all(b"a")?;
7070
stage_add_file(repo_path, file_path);
71-
commit(repo_path, "commit1");
71+
commit(repo_path, "commit1").unwrap();
7272
File::create(&root.join(file_path))?.write_all(b"a")?;
7373
stage_add_file(repo_path, file_path);
74-
let oid2 = commit(repo_path, "commit2");
74+
let oid2 = commit(repo_path, "commit2").unwrap();
7575

7676
let mut items = Vec::new();
7777
let mut walk = LogWalker::new(&repo);
@@ -92,10 +92,10 @@ mod tests {
9292

9393
File::create(&root.join(file_path))?.write_all(b"a")?;
9494
stage_add_file(repo_path, file_path);
95-
commit(repo_path, "commit1");
95+
commit(repo_path, "commit1").unwrap();
9696
File::create(&root.join(file_path))?.write_all(b"a")?;
9797
stage_add_file(repo_path, file_path);
98-
let oid2 = commit(repo_path, "commit2");
98+
let oid2 = commit(repo_path, "commit2").unwrap();
9999

100100
let mut items = Vec::new();
101101
let mut walk = LogWalker::new(&repo);

asyncgit/src/sync/reset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ mod tests {
207207
}
208208

209209
assert!(stage_add_all(repo_path, "*"));
210-
commit(repo_path, "msg");
210+
commit(repo_path, "msg").unwrap();
211211

212212
{
213213
File::create(&root.join("foo/file1.txt"))?

asyncgit/src/sync/utils.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! sync git api (various methods)
22
3-
use git2::{IndexAddOption, Oid, Repository, RepositoryOpenFlags};
3+
use git2::{
4+
Error, IndexAddOption, Oid, Repository, RepositoryOpenFlags,
5+
};
46
use scopetime::scope_time;
57
use std::path::Path;
68

@@ -31,19 +33,18 @@ pub fn repo(repo_path: &str) -> Repository {
3133
}
3234

3335
/// this does not run any git hooks
34-
pub fn commit(repo_path: &str, msg: &str) -> Oid {
36+
pub fn commit(repo_path: &str, msg: &str) -> Result<Oid, Error> {
3537
scope_time!("commit");
3638

3739
let repo = repo(repo_path);
3840

39-
let signature = repo.signature().unwrap();
40-
let mut index = repo.index().unwrap();
41-
let tree_id = index.write_tree().unwrap();
42-
let tree = repo.find_tree(tree_id).unwrap();
41+
let signature = repo.signature()?;
42+
let mut index = repo.index()?;
43+
let tree_id = index.write_tree()?;
44+
let tree = repo.find_tree(tree_id)?;
4345

4446
let parents = if let Ok(reference) = repo.head() {
45-
let parent =
46-
repo.find_commit(reference.target().unwrap()).unwrap();
47+
let parent = repo.find_commit(reference.target().unwrap())?;
4748
vec![parent]
4849
} else {
4950
Vec::new()
@@ -59,7 +60,6 @@ pub fn commit(repo_path: &str, msg: &str) -> Oid {
5960
&tree,
6061
parents.as_slice(),
6162
)
62-
.unwrap()
6363
}
6464

6565
/// add a file diff from workingdir to stage (will not add removed files see `stage_addremoved`)
@@ -144,7 +144,7 @@ mod tests {
144144

145145
assert_eq!(get_statuses(repo_path), (0, 1));
146146

147-
commit(repo_path, "commit msg");
147+
commit(repo_path, "commit msg").unwrap();
148148

149149
assert_eq!(get_statuses(repo_path), (0, 0));
150150
}
@@ -169,7 +169,7 @@ mod tests {
169169

170170
assert_eq!(get_statuses(repo_path), (0, 1));
171171

172-
commit(repo_path, "commit msg");
172+
commit(repo_path, "commit msg").unwrap();
173173

174174
assert_eq!(get_statuses(repo_path), (0, 0));
175175
}
@@ -256,7 +256,7 @@ mod tests {
256256

257257
assert_eq!(stage_add_file(repo_path, file_path), true);
258258

259-
commit(repo_path, "commit msg");
259+
commit(repo_path, "commit msg").unwrap();
260260

261261
// delete the file now
262262
assert_eq!(remove_file(full_path).is_ok(), true);

src/components/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl CommitComponent {
134134
return;
135135
}
136136

137-
sync::commit(CWD, &self.msg);
137+
sync::commit(CWD, &self.msg).unwrap();
138138
if let HookResult::NotOk(e) = sync::hooks_post_commit(CWD) {
139139
error!("post-commit hook error: {}", e);
140140
self.queue.borrow_mut().push_back(

0 commit comments

Comments
 (0)