From 4cee9975d5dfa4f76b412426a6eb5cca999b4885 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Fri, 17 Apr 2026 16:07:01 +0800 Subject: [PATCH] fix(api): fix commit route order to prevent InvalidOid("reflog") error Move specific routes (/commits/reflog, /commits/branches, /commits/tags) before parameterized routes (/commits/{oid}) to avoid route shadowing. Previously, /commits/reflog was matched by /commits/{oid} with oid="reflog", causing InvalidOid("reflog") errors. Also fixes other potential route shadowing issues in commit routes. --- libs/api/git/mod.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/api/git/mod.rs b/libs/api/git/mod.rs index 202dc25..fbdf83e 100644 --- a/libs/api/git/mod.rs +++ b/libs/api/git/mod.rs @@ -125,7 +125,7 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) { "/branches/is-conflicted", web::get().to(branch::git_branch_is_conflicted), ) - // commit + // commit - specific routes first, then parameterized routes .route("/commits", web::get().to(commit::git_commit_log)) .route("/commits/count", web::get().to(commit::git_commit_count)) .route("/commits", web::post().to(commit::git_commit_create)) @@ -139,6 +139,13 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) { "/commits/resolve/{rev}", web::get().to(commit::git_commit_resolve_rev), ) + .route("/commits/reflog", web::get().to(commit::git_commit_reflog)) + .route( + "/commits/branches", + web::get().to(commit::git_commit_branches), + ) + .route("/commits/tags", web::get().to(commit::git_commit_tags)) + // parameterized routes with {oid} .route("/commits/{oid}", web::get().to(commit::git_commit_get)) .route("/commits/{oid}", web::patch().to(commit::git_commit_amend)) .route( @@ -193,11 +200,6 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) { "/commits/{oid}/refs", web::get().to(commit::git_commit_refs), ) - .route( - "/commits/branches", - web::get().to(commit::git_commit_branches), - ) - .route("/commits/tags", web::get().to(commit::git_commit_tags)) .route( "/commits/{oid}/is-tip", web::get().to(commit::git_commit_is_tip), @@ -206,7 +208,6 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) { "/commits/{oid}/ref-count", web::get().to(commit::git_commit_ref_count), ) - .route("/commits/reflog", web::get().to(commit::git_commit_reflog)) .route( "/commits/{oid}/ancestors", web::get().to(commit::git_commit_ancestors),