fix(api): fix branch route order to prevent shadowing
Some checks are pending
CI / Rust Lint & Check (push) Waiting to run
CI / Rust Tests (push) Waiting to run
CI / Frontend Lint & Type Check (push) Waiting to run
CI / Frontend Build (push) Blocked by required conditions

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}.
This commit is contained in:
ZhenYi 2026-04-17 16:11:23 +08:00
parent 1272615d50
commit ee4ff6c752

View File

@ -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}/content", web::get().to(blob::git_blob_content))
.route("/blob/{oid}/size", web::get().to(blob::git_blob_size)) .route("/blob/{oid}/size", web::get().to(blob::git_blob_size))
.route("/readme", web::get().to(blob::git_readme)) .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", web::get().to(branch::git_branch_list))
.route( .route(
"/branches/summary", "/branches/summary",
web::get().to(branch::git_branch_summary), web::get().to(branch::git_branch_summary),
) )
.route("/branches", web::post().to(branch::git_branch_create)) .route("/branches", web::post().to(branch::git_branch_create))
// NOTE: /branches/current MUST be before /branches/{name} to avoid being shadowed
.route( .route(
"/branches/current", "/branches/current",
web::get().to(branch::git_branch_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( .route(
"/branches/remote/{name}", "/branches/remote/{name}",
web::delete().to(branch::git_branch_delete_remote), web::delete().to(branch::git_branch_delete_remote),
@ -125,6 +103,28 @@ pub fn init_git_routes(cfg: &mut web::ServiceConfig) {
"/branches/is-conflicted", "/branches/is-conflicted",
web::get().to(branch::git_branch_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 // commit - specific routes first, then parameterized routes
.route("/commits", web::get().to(commit::git_commit_log)) .route("/commits", web::get().to(commit::git_commit_log))
.route("/commits/count", web::get().to(commit::git_commit_count)) .route("/commits/count", web::get().to(commit::git_commit_count))