Skip to content

Commit 717078d

Browse files
authored
Merge pull request #4800 from gitbutlerapp/update-change-reference-for-branch
add api for updating change references
2 parents c8caabb + af6fdc3 commit 717078d

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

apps/desktop/src/lib/vbranches/branchController.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class BranchController {
118118
/*
119119
* Pushes a change reference to (converted to a git reference to a commit) to the remote
120120
* @param branchId
121-
* @param reference in the format refs/remotes/origin/my-branch (must be remote)
121+
* @param reference in the format refs/remotes/origin/my-branch (must be remote, must already exist)
122122
* @param changeId The change id that is being pushed
123123
*/
124124
async pushChangeReference(branchId: string, referenceName: string, withForce: boolean = false) {
@@ -134,6 +134,25 @@ export class BranchController {
134134
}
135135
}
136136

137+
/*
138+
* Updates a change reference to point to a new change
139+
* @param branchId
140+
* @param reference in the format refs/remotes/origin/my-branch (must be remote, must already exist)
141+
* @param newChangeId The change id to point the reference to
142+
*/
143+
async updateChangeReference(branchId: string, referenceName: string, newChangeId: string) {
144+
try {
145+
await invoke<void>('update_change_reference', {
146+
projectId: this.projectId,
147+
branchId: branchId,
148+
name: referenceName,
149+
newChangeId: newChangeId
150+
});
151+
} catch (err) {
152+
showError('Failed to update change reference', err);
153+
}
154+
}
155+
137156
async updateBranchRemoteName(branchId: string, upstream: string) {
138157
try {
139158
await invoke<void>('update_virtual_branch', {

crates/gitbutler-branch-actions/src/actions.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,17 @@ impl VirtualBranchActions {
401401
gitbutler_repo::push_change_reference(&ctx, branch_id, name, with_force, &helper)
402402
}
403403

404+
pub fn update_change_reference(
405+
&self,
406+
project: &Project,
407+
branch_id: BranchId,
408+
name: ReferenceName,
409+
new_change_id: String,
410+
) -> Result<ChangeReference> {
411+
let ctx = open_with_verify(project)?;
412+
gitbutler_repo::update_change_reference(&ctx, branch_id, name, new_change_id)
413+
}
414+
404415
pub fn reorder_commit(
405416
&self,
406417
project: &Project,

crates/gitbutler-tauri/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ fn main() {
175175
virtual_branches::commands::insert_blank_commit,
176176
virtual_branches::commands::create_change_reference,
177177
virtual_branches::commands::push_change_reference,
178+
virtual_branches::commands::update_change_reference,
178179
virtual_branches::commands::reorder_commit,
179180
virtual_branches::commands::update_commit_message,
180181
virtual_branches::commands::list_remote_branches,

crates/gitbutler-tauri/src/virtual_branches.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,22 @@ pub mod commands {
428428
Ok(())
429429
}
430430

431+
#[tauri::command(async)]
432+
#[instrument(skip(projects, windows), err(Debug))]
433+
pub fn update_change_reference(
434+
windows: State<'_, WindowState>,
435+
projects: State<'_, projects::Controller>,
436+
project_id: ProjectId,
437+
branch_id: BranchId,
438+
name: ReferenceName,
439+
new_change_id: String,
440+
) -> Result<(), Error> {
441+
let project = projects.get(project_id)?;
442+
VirtualBranchActions.update_change_reference(&project, branch_id, name, new_change_id)?;
443+
emit_vbranches(&windows, project_id);
444+
Ok(())
445+
}
446+
431447
#[tauri::command(async)]
432448
#[instrument(skip(projects, windows), err(Debug))]
433449
pub fn reorder_commit(

0 commit comments

Comments
 (0)