aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/get_routes.rs6
-rw-r--r--src/main.rs10
-rw-r--r--src/tests.rs9
3 files changed, 15 insertions, 10 deletions
diff --git a/src/get_routes.rs b/src/get_routes.rs
index 112cf6b..79b7cb5 100644
--- a/src/get_routes.rs
+++ b/src/get_routes.rs
@@ -438,7 +438,7 @@ fn remove_blob<C: Controller>(
}
pub fn view_tree<C: Controller>(
- tree: Result<Tree, git2::Error>,
+ tree: Option<Tree>,
controller: &C,
ctx: &Context,
parts: &Parts,
@@ -454,7 +454,7 @@ pub fn view_tree<C: Controller>(
.push_str("<li><a href='..' title='go to parent directory'>../</a></li>");
}
- if let Ok(tree) = &tree {
+ if let Some(tree) = &tree {
let mut entries: Vec<_> = tree.iter().collect();
entries.sort_by_key(|a| a.kind().unwrap().raw());
@@ -477,7 +477,7 @@ pub fn view_tree<C: Controller>(
}
page.body.push_str("</ul>");
- controller.before_return_tree_page(&mut page, tree.ok(), ctx, parts);
+ controller.before_return_tree_page(&mut page, tree, ctx, parts);
Ok(page.into())
}
diff --git a/src/main.rs b/src/main.rs
index 8f756ef..73de77d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -367,14 +367,14 @@ async fn build_response<C: Controller>(
return post_routes::build_response(origin, &params, controller, ctx, body, parts).await;
}
- let tree = ctx.branch_head()?.tree();
+ let tree = ctx.branch_head().ok().and_then(|c| c.tree().ok());
if ctx.path.components().next().is_none() {
return get_routes::view_tree(tree, controller, &ctx, parts);
}
- match tree.and_then(|t| t.get_path(ctx.path.as_ref())) {
- Ok(entr) => match entr.kind().unwrap() {
+ match tree.and_then(|t| t.get_path(ctx.path.as_ref()).ok()) {
+ Some(entr) => match entr.kind().unwrap() {
ObjectType::Blob => {
if unsanitized_path.ends_with('/') {
return Ok(Builder::new()
@@ -396,11 +396,11 @@ async fn build_response<C: Controller>(
if !unsanitized_path.ends_with('/') {
return Err(Error::MissingTrailingSlash(parts.uri.path().to_owned()));
}
- get_routes::view_tree(ctx.repo.find_tree(entr.id()), controller, &ctx, parts)
+ get_routes::view_tree(ctx.repo.find_tree(entr.id()).ok(), controller, &ctx, parts)
}
_other => panic!("unexpected object type"),
},
- Err(_) => {
+ None => {
if unsanitized_path.ends_with('/') {
return Err(Error::NotFound("directory not found".into()));
}
diff --git a/src/tests.rs b/src/tests.rs
index 3eb71ec..1dc64ec 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -98,7 +98,12 @@ async fn test_missing_branch() {
.unwrap(),
)
.await;
- assert_eq!(res.status(), 404); // branch not found
+ assert_eq!(res.status(), 200);
+ assert!(res
+ .into_body()
+ .into_text()
+ .await
+ .contains("create files by editing the URL"));
- // TODO: create commit with file and test that it is retrievable
+ // TODO: create file and test that it is retrievable
}