aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock56
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs26
-rw-r--r--src/main.rs2
4 files changed, 78 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 328f96c..4c250ac 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -32,6 +32,7 @@ name = "git-todo"
version = "0.0.1"
dependencies = [
"git2",
+ "thiserror",
]
[[package]]
@@ -162,6 +163,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
+name = "proc-macro2"
+version = "1.0.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.41"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
+[[package]]
+name = "thiserror"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "tinyvec"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -186,6 +236,12 @@ dependencies = [
]
[[package]]
+name = "unicode-xid"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
+
+[[package]]
name = "url"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index cf539a5..834bb4c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,3 +5,4 @@ edition = "2018"
[dependencies]
git2 = "0.13.11"
+thiserror = "1.0.20"
diff --git a/src/lib.rs b/src/lib.rs
index bc3c9b0..0b64b22 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,6 +3,14 @@
use std::io::Write;
use git2::{Repository, Tree};
+use thiserror::Error;
+
+
+#[derive(Error, Debug)]
+pub enum Error {
+ #[error(transparent)]
+ Git(#[from] git2::Error),
+}
pub struct Todos<'a> {
@@ -10,8 +18,12 @@ pub struct Todos<'a> {
}
impl Todos<'_> {
- pub fn write_since<W: Write>(&self, tree: Tree<'_>, write_to: &mut W) {
- let diff = self.repo.diff_tree_to_workdir(Some(&tree), None).unwrap();
+ pub fn write_since<W: Write>(
+ &self,
+ tree: Tree<'_>,
+ write_to: &mut W,
+ ) -> Result<(), Error> {
+ let diff = self.repo.diff_tree_to_workdir(Some(&tree), None)?;
diff.foreach(
&mut |_file, _progress| {
@@ -45,12 +57,14 @@ impl Todos<'_> {
true
}
),
- ).unwrap();
+ )?;
+
+ Ok(())
}
- pub fn master_tree(&self) -> Tree<'_> {
- let master = self.repo.find_branch("master", git2::BranchType::Local).unwrap();
+ pub fn master_tree(&self) -> Result<Tree<'_>, Error> {
+ let master = self.repo.find_branch("master", git2::BranchType::Local)?;
- master.get().peel_to_tree().unwrap()
+ Ok(master.get().peel_to_tree()?)
}
}
diff --git a/src/main.rs b/src/main.rs
index 48e8f5d..f743256 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,5 +9,5 @@ fn main() {
let repo = Repository::open(".").unwrap();
let todos = Todos { repo: &repo };
- todos.write_since(todos.master_tree(), &mut std::io::stdout());
+ todos.write_since(todos.master_tree().unwrap(), &mut std::io::stdout()).unwrap();
}