mygit

[UNMAINTAINED] A cgit/webgit alternative, written in Rust
Log | Files | Refs | README | LICENSE

commit 4984c7cca22b868286d001f009228cebcba97af6
parent 8c30d6d0c9cf70a9d69a34b7d02f7e3205dcdcf4
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Thu, 15 Jul 2021 15:44:19 +0200

redirect lightweight tag

Lightweight tags are just commits so they are redirected
to repo/commit/...

Diffstat:
Msrc/main.rs | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -487,10 +487,19 @@ struct RepoTagTemplate<'a> { async fn repo_tag(req: Request<()>) -> tide::Result { let repo = repo_from_request(req.param("repo_name")?)?; - let tag = repo.revparse_single(req.param("tag")?)?.peel_to_tag()?; + let tag = repo.revparse_single(req.param("tag")?)?.peel_to_tag(); - let tmpl = RepoTagTemplate { repo: &repo, tag }; - Ok(tmpl.into()) + if let Ok(tag) = tag { + let tmpl = RepoTagTemplate { repo: &repo, tag }; + Ok(tmpl.into()) + } else { + Ok(tide::Redirect::permanent(format!( + "/{}/commit/{}", + req.param("repo_name")?, + req.param("tag")? + )) + .into()) + } } #[derive(Template)]