Feature: Supports remote branch deletion

This commit is contained in:
xintaofei
2026-04-01 12:41:15 +08:00
parent c25e4062b9
commit b98f50340f
16 changed files with 153 additions and 14 deletions

View File

@@ -2055,6 +2055,45 @@ pub async fn git_delete_branch(
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}
pub(crate) async fn git_delete_remote_branch_core(
path: &str,
remote: &str,
branch: &str,
credentials: Option<&GitCredentials>,
db: &AppDatabase,
data_dir: &std::path::Path,
) -> Result<String, AppCommandError> {
let mut cmd = crate::process::tokio_command("git");
cmd.args(["push", remote, "--delete", branch])
.current_dir(path);
prepare_remote_git_cmd_with_remote(&mut cmd, path, Some(remote), credentials, db, data_dir)
.await;
let output = cmd.output().await.map_err(AppCommandError::io)?;
if !output.status.success() {
return Err(classify_remote_git_error("push --delete", &output.stderr));
}
Ok(String::from_utf8_lossy(&output.stderr).trim().to_string())
}
#[cfg(feature = "tauri-runtime")]
#[cfg_attr(feature = "tauri-runtime", tauri::command)]
pub async fn git_delete_remote_branch(
path: String,
remote: String,
branch: String,
credentials: Option<GitCredentials>,
db: tauri::State<'_, AppDatabase>,
app_handle: tauri::AppHandle,
) -> Result<String, AppCommandError> {
let data_dir = app_handle.path().app_data_dir().map_err(|e| {
AppCommandError::external_command("Failed to resolve app data dir", e.to_string())
})?;
git_delete_remote_branch_core(&path, &remote, &branch, credentials.as_ref(), &db, &data_dir)
.await
}
#[cfg_attr(feature = "tauri-runtime", tauri::command)]
pub async fn git_list_conflicts(path: String) -> Result<Vec<String>, AppCommandError> {
detect_conflicts(&path).await

View File

@@ -279,6 +279,7 @@ mod tauri_app {
folders::git_merge,
folders::git_rebase,
folders::git_delete_branch,
folders::git_delete_remote_branch,
folders::git_list_conflicts,
folders::git_conflict_file_versions,
folders::git_resolve_conflict,

View File

@@ -451,6 +451,32 @@ pub async fn git_delete_branch(
Ok(Json(()))
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GitDeleteRemoteBranchParams {
pub path: String,
pub remote: String,
pub branch: String,
pub credentials: Option<GitCredentials>,
}
pub async fn git_delete_remote_branch(
Extension(state): Extension<Arc<AppState>>,
Json(params): Json<GitDeleteRemoteBranchParams>,
) -> Result<Json<()>, AppCommandError> {
let db = &state.db;
folder_commands::git_delete_remote_branch_core(
&params.path,
&params.remote,
&params.branch,
params.credentials.as_ref(),
db,
&state.data_dir,
)
.await?;
Ok(Json(()))
}
pub async fn git_list_conflicts(
Json(params): Json<PathParams>,
) -> Result<Json<Vec<String>>, AppCommandError> {

View File

@@ -106,6 +106,7 @@ pub fn build_router(state: Arc<AppState>, token: String, static_dir: std::path::
.route("/git_fetch", post(handlers::git::git_fetch))
.route("/git_commit", post(handlers::git::git_commit))
.route("/git_fetch_remote", post(handlers::git::git_fetch_remote))
.route("/git_delete_remote_branch", post(handlers::git::git_delete_remote_branch))
.route("/clone_repository", post(handlers::git::clone_repository))
// ─── Files ───
.route("/read_file_preview", post(handlers::files::read_file_preview))