From 0e6901c06399624cb85f31aab7e69be79d013da5 Mon Sep 17 00:00:00 2001 From: wuyangji <694410194@qq.com> Date: Thu, 14 May 2026 10:19:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(app-server):=20=E6=94=B9=E4=B8=BA=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E6=89=A7=E8=A1=8C=20Git=20=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cortex-app-server/src/api/git.rs | 80 ++++++++++++++++++---------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/src/cortex-app-server/src/api/git.rs b/src/cortex-app-server/src/api/git.rs index c756ed789..f0e0df9d9 100644 --- a/src/cortex-app-server/src/api/git.rs +++ b/src/cortex-app-server/src/api/git.rs @@ -1,6 +1,6 @@ //! Git operations endpoints. -use std::process::Command; +use tokio::process::Command; use axum::{Json, extract::Query}; @@ -17,7 +17,8 @@ use super::types::{ pub async fn git_status(Query(query): Query) -> AppResult> { let output = Command::new("git") .args(["-C", &query.path, "status", "--porcelain=v2", "-b"]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -139,7 +140,8 @@ fn status_char_to_string(c: &str) -> String { pub async fn git_branch(Query(query): Query) -> AppResult> { let output = Command::new("git") .args(["-C", &query.path, "branch", "--show-current"]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -155,7 +157,8 @@ pub async fn git_branches(Query(query): Query) -> AppResult { @@ -213,7 +216,8 @@ pub async fn git_branches(Query(query): Query) -> AppResult) -> AppResult { @@ -385,7 +389,8 @@ fn parse_diff_with_stats(diff: &str) -> (Vec, usize, usize) { pub async fn git_blame(Query(query): Query) -> AppResult> { let output = Command::new("git") .args(["-C", &query.path, "blame", "--porcelain", &query.file]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -469,7 +474,8 @@ pub async fn git_log(Query(query): Query) -> AppResult { @@ -548,7 +554,8 @@ pub async fn git_stage(Json(req): Json) -> AppResult) -> AppResult) -> AppResult) -> AppResult> { let _ = Command::new("git") .args(["-C", &req.path, "add", "-A"]) - .output(); + .output() + .await; Ok(Json(serde_json::json!({ "success": true }))) } @@ -580,7 +589,8 @@ pub async fn git_unstage_all( ) -> AppResult> { let _ = Command::new("git") .args(["-C", &req.path, "reset", "HEAD"]) - .output(); + .output() + .await; Ok(Json(serde_json::json!({ "success": true }))) } @@ -589,7 +599,8 @@ pub async fn git_unstage_all( pub async fn git_commit(Json(req): Json) -> AppResult> { let output = Command::new("git") .args(["-C", &req.path, "commit", "-m", &req.message]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -606,7 +617,8 @@ pub async fn git_checkout( ) -> AppResult> { let output = Command::new("git") .args(["-C", &req.path, "checkout", &req.branch]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -624,7 +636,10 @@ pub async fn git_checkout( /// Push to remote. pub async fn git_push(Json(req): Json) -> AppResult> { - let output = Command::new("git").args(["-C", &req.path, "push"]).output(); + let output = Command::new("git") + .args(["-C", &req.path, "push"]) + .output() + .await; match output { Ok(output) => { @@ -645,7 +660,10 @@ pub async fn git_push(Json(req): Json) -> AppResult) -> AppResult> { - let output = Command::new("git").args(["-C", &req.path, "pull"]).output(); + let output = Command::new("git") + .args(["-C", &req.path, "pull"]) + .output() + .await; match output { Ok(output) => { @@ -668,7 +686,8 @@ pub async fn git_pull(Json(req): Json) -> AppResult) -> AppResult> { let output = Command::new("git") .args(["-C", &req.path, "fetch", "--all", "--prune"]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -693,7 +712,8 @@ pub async fn git_discard(Json(req): Json) -> AppResult) -> AppResult { @@ -761,7 +782,8 @@ pub async fn git_delete_branch( let output = Command::new("git") .args(["-C", &req.path, "branch", delete_flag, &req.name]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -793,7 +815,7 @@ pub async fn git_merge(Json(req): Json) -> AppResult { @@ -823,7 +845,8 @@ pub async fn git_stash_list( ) -> AppResult> { let output = Command::new("git") .args(["-C", &query.path, "stash", "list", "--format=%gd|%H|%s|%aI"]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -886,7 +909,7 @@ pub async fn git_stash_create( args.push(msg); } - let output = Command::new("git").args(&args).output(); + let output = Command::new("git").args(&args).output().await; match output { Ok(output) => { @@ -919,7 +942,8 @@ pub async fn git_stash_apply( let output = Command::new("git") .args(["-C", &req.path, "stash", "apply", &stash_ref]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -947,7 +971,8 @@ pub async fn git_stash_pop( let output = Command::new("git") .args(["-C", &req.path, "stash", "pop", &stash_ref]) - .output(); + .output() + .await; match output { Ok(output) => { @@ -975,7 +1000,8 @@ pub async fn git_stash_drop( let output = Command::new("git") .args(["-C", &req.path, "stash", "drop", &stash_ref]) - .output(); + .output() + .await; match output { Ok(output) => {