diff --git a/apps/desktop/src/lib/vbranches/branchController.ts b/apps/desktop/src/lib/vbranches/branchController.ts index 1c997350a7..1b6383777d 100644 --- a/apps/desktop/src/lib/vbranches/branchController.ts +++ b/apps/desktop/src/lib/vbranches/branchController.ts @@ -118,7 +118,7 @@ export class BranchController { /* * Pushes a change reference to (converted to a git reference to a commit) to the remote * @param branchId - * @param reference in the format refs/remotes/origin/my-branch (must be remote) + * @param reference in the format refs/remotes/origin/my-branch (must be remote, must already exist) * @param changeId The change id that is being pushed */ async pushChangeReference(branchId: string, referenceName: string, withForce: boolean = false) { @@ -134,6 +134,25 @@ export class BranchController { } } + /* + * Updates a change reference to point to a new change + * @param branchId + * @param reference in the format refs/remotes/origin/my-branch (must be remote, must already exist) + * @param newChangeId The change id to point the reference to + */ + async updateChangeReference(branchId: string, referenceName: string, newChangeId: string) { + try { + await invoke('update_change_reference', { + projectId: this.projectId, + branchId: branchId, + name: referenceName, + newChangeId: newChangeId + }); + } catch (err) { + showError('Failed to update change reference', err); + } + } + async updateBranchRemoteName(branchId: string, upstream: string) { try { await invoke('update_virtual_branch', { diff --git a/crates/gitbutler-branch-actions/src/actions.rs b/crates/gitbutler-branch-actions/src/actions.rs index 4629682228..6d9363a9eb 100644 --- a/crates/gitbutler-branch-actions/src/actions.rs +++ b/crates/gitbutler-branch-actions/src/actions.rs @@ -401,6 +401,17 @@ impl VirtualBranchActions { gitbutler_repo::push_change_reference(&ctx, branch_id, name, with_force, &helper) } + pub fn update_change_reference( + &self, + project: &Project, + branch_id: BranchId, + name: ReferenceName, + new_change_id: String, + ) -> Result { + let ctx = open_with_verify(project)?; + gitbutler_repo::update_change_reference(&ctx, branch_id, name, new_change_id) + } + pub fn reorder_commit( &self, project: &Project, diff --git a/crates/gitbutler-tauri/src/main.rs b/crates/gitbutler-tauri/src/main.rs index ea8a323e58..c9bf25e085 100644 --- a/crates/gitbutler-tauri/src/main.rs +++ b/crates/gitbutler-tauri/src/main.rs @@ -175,6 +175,7 @@ fn main() { virtual_branches::commands::insert_blank_commit, virtual_branches::commands::create_change_reference, virtual_branches::commands::push_change_reference, + virtual_branches::commands::update_change_reference, virtual_branches::commands::reorder_commit, virtual_branches::commands::update_commit_message, virtual_branches::commands::list_remote_branches, diff --git a/crates/gitbutler-tauri/src/virtual_branches.rs b/crates/gitbutler-tauri/src/virtual_branches.rs index caf346fd92..b1d6054ab3 100644 --- a/crates/gitbutler-tauri/src/virtual_branches.rs +++ b/crates/gitbutler-tauri/src/virtual_branches.rs @@ -428,6 +428,22 @@ pub mod commands { Ok(()) } + #[tauri::command(async)] + #[instrument(skip(projects, windows), err(Debug))] + pub fn update_change_reference( + windows: State<'_, WindowState>, + projects: State<'_, projects::Controller>, + project_id: ProjectId, + branch_id: BranchId, + name: ReferenceName, + new_change_id: String, + ) -> Result<(), Error> { + let project = projects.get(project_id)?; + VirtualBranchActions.update_change_reference(&project, branch_id, name, new_change_id)?; + emit_vbranches(&windows, project_id); + Ok(()) + } + #[tauri::command(async)] #[instrument(skip(projects, windows), err(Debug))] pub fn reorder_commit(