Skip to content

Commit

Permalink
add api for updating change references
Browse files Browse the repository at this point in the history
  • Loading branch information
krlvi committed Aug 30, 2024
1 parent c8caabb commit af6fdc3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
21 changes: 20 additions & 1 deletion apps/desktop/src/lib/vbranches/branchController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<void>('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<void>('update_virtual_branch', {
Expand Down
11 changes: 11 additions & 0 deletions crates/gitbutler-branch-actions/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChangeReference> {
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,
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions crates/gitbutler-tauri/src/virtual_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit af6fdc3

Please sign in to comment.