From ee4ff6c752297e82b272e985b1a37e277e110c46 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Fri, 17 Apr 2026 16:11:23 +0800 Subject: [PATCH] fix(api): fix branch route order to prevent shadowing Move all specific branch routes before /branches/{name} to prevent route shadowing. Previously, routes like /branches/rename, /branches/move, /branches/upstream, /branches/diff, etc. were shadowed by /branches/{name}. --- libs/api/git/mod.rs | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/libs/api/git/mod.rs b/libs/api/git/mod.rs index 80c6ca0..0733f04 100644 --- a/libs/api/git/mod.rs +++ b/libs/api/git/mod.rs @@ -54,39 +54,17 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) { .route("/blob/{oid}/content", web::get().to(blob::git_blob_content)) .route("/blob/{oid}/size", web::get().to(blob::git_blob_size)) .route("/readme", web::get().to(blob::git_readme)) - // branch + // branch - specific routes first, then parameterized routes .route("/branches", web::get().to(branch::git_branch_list)) .route( "/branches/summary", web::get().to(branch::git_branch_summary), ) .route("/branches", web::post().to(branch::git_branch_create)) - // NOTE: /branches/current MUST be before /branches/{name} to avoid being shadowed .route( "/branches/current", web::get().to(branch::git_branch_current), ) - .route("/branches/{name}", web::get().to(branch::git_branch_get)) - .route( - "/branches/{name}", - web::delete().to(branch::git_branch_delete), - ) - .route( - "/branches/{name}/exists", - web::get().to(branch::git_branch_exists), - ) - .route( - "/branches/{name}/is-head", - web::get().to(branch::git_branch_is_head), - ) - .route( - "/branches/{name}/upstream", - web::get().to(branch::git_branch_upstream), - ) - .route( - "/branches/{name}/tracking-difference", - web::get().to(branch::git_branch_tracking_difference), - ) .route( "/branches/remote/{name}", web::delete().to(branch::git_branch_delete_remote), @@ -125,6 +103,28 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) { "/branches/is-conflicted", web::get().to(branch::git_branch_is_conflicted), ) + // parameterized routes with {name} + .route("/branches/{name}", web::get().to(branch::git_branch_get)) + .route( + "/branches/{name}", + web::delete().to(branch::git_branch_delete), + ) + .route( + "/branches/{name}/exists", + web::get().to(branch::git_branch_exists), + ) + .route( + "/branches/{name}/is-head", + web::get().to(branch::git_branch_is_head), + ) + .route( + "/branches/{name}/upstream", + web::get().to(branch::git_branch_upstream), + ) + .route( + "/branches/{name}/tracking-difference", + web::get().to(branch::git_branch_tracking_difference), + ) // 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))