|
1 | 1 | use serde::de::DeserializeOwned; |
2 | 2 | use serde::Serialize; |
3 | | -use serde_json::Value; |
| 3 | +use serde_json::{json, Value}; |
4 | 4 | use tauri::{AppHandle, State}; |
5 | 5 |
|
6 | 6 | use crate::remote_backend; |
7 | 7 | use crate::shared::{git_rpc, git_ui_core}; |
8 | 8 | use crate::state::AppState; |
9 | 9 | use crate::types::{ |
10 | 10 | GitCommitDiff, GitFileDiff, GitHubIssuesResponse, GitHubPullRequestComment, |
11 | | - GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, |
| 11 | + GitHubPullRequestDiff, GitHubPullRequestsResponse, GitLogResponse, GitSelectionApplyResult, |
| 12 | + GitSelectionLine, |
12 | 13 | }; |
13 | 14 |
|
14 | 15 | fn git_remote_params<T: Serialize>(request: &T) -> Result<Value, String> { |
@@ -187,6 +188,63 @@ pub(crate) async fn stage_git_all( |
187 | 188 | git_ui_core::stage_git_all_core(&state.workspaces, workspace_id).await |
188 | 189 | } |
189 | 190 |
|
| 191 | +#[tauri::command] |
| 192 | +pub(crate) async fn stage_git_selection( |
| 193 | + workspace_id: String, |
| 194 | + path: String, |
| 195 | + op: String, |
| 196 | + source: String, |
| 197 | + lines: Vec<GitSelectionLine>, |
| 198 | + state: State<'_, AppState>, |
| 199 | + app: AppHandle, |
| 200 | +) -> Result<GitSelectionApplyResult, String> { |
| 201 | + try_remote_typed!( |
| 202 | + state, |
| 203 | + app, |
| 204 | + "stage_git_selection", |
| 205 | + json!({ |
| 206 | + "workspaceId": &workspace_id, |
| 207 | + "path": &path, |
| 208 | + "op": &op, |
| 209 | + "source": &source, |
| 210 | + "lines": &lines |
| 211 | + }), |
| 212 | + GitSelectionApplyResult |
| 213 | + ); |
| 214 | + git_ui_core::stage_git_selection_core(&state.workspaces, workspace_id, path, op, source, lines) |
| 215 | + .await |
| 216 | +} |
| 217 | + |
| 218 | +#[tauri::command] |
| 219 | +pub(crate) async fn apply_git_display_hunk( |
| 220 | + workspace_id: String, |
| 221 | + path: String, |
| 222 | + display_hunk_id: String, |
| 223 | + state: State<'_, AppState>, |
| 224 | + app: AppHandle, |
| 225 | +) -> Result<GitSelectionApplyResult, String> { |
| 226 | + let request = git_rpc::GitDisplayHunkActionRequest { |
| 227 | + workspace_id: workspace_id.clone(), |
| 228 | + path: path.clone(), |
| 229 | + display_hunk_id: display_hunk_id.clone(), |
| 230 | + }; |
| 231 | + try_remote_typed!( |
| 232 | + state, |
| 233 | + app, |
| 234 | + git_rpc::METHOD_APPLY_GIT_DISPLAY_HUNK, |
| 235 | + git_remote_params(&request)?, |
| 236 | + GitSelectionApplyResult |
| 237 | + ); |
| 238 | + git_ui_core::apply_git_display_hunk_core( |
| 239 | + &state.workspaces, |
| 240 | + &state.app_settings, |
| 241 | + workspace_id, |
| 242 | + path, |
| 243 | + display_hunk_id, |
| 244 | + ) |
| 245 | + .await |
| 246 | +} |
| 247 | + |
190 | 248 | #[tauri::command] |
191 | 249 | pub(crate) async fn unstage_git_file( |
192 | 250 | workspace_id: String, |
|
0 commit comments