add commands for pushing change references

This commit is contained in:
Kiril Videlov 2024-08-26 21:38:40 +02:00
parent cef701796d
commit 4b5a8d14ef
No known key found for this signature in database
GPG Key ID: A4C733025427C471
5 changed files with 68 additions and 3 deletions

View File

@ -94,6 +94,12 @@
createRefModal.show(commit);
}
function pushCommitRef(commit: DetailedCommit) {
if (branch && commit.remoteRef) {
branchController.pushChangeReference(branch.id, commit.remoteRef);
}
}
function openCommitMessageModal(e: Event) {
e.stopPropagation();
@ -395,7 +401,7 @@
icon="edit-small"
onclick={openCommitMessageModal}>Edit message</Button
>
{#if $branchStacking}
{#if $branchStacking && commit instanceof DetailedCommit && !commit.remoteRef}
<Button
size="tag"
style="ghost"
@ -404,6 +410,17 @@
onclick={(e: Event) => {openCreateRefModal(e, commit)}}>Create ref</Button
>
{/if}
{#if $branchStacking && commit instanceof DetailedCommit && commit.remoteRef}
<Button
size="tag"
style="ghost"
outline
icon="remote"
onclick={() => {
pushCommitRef(commit);
}}>Push ref</Button
>
{/if}
{/if}
{#if canEdit() && project.succeedingRebases}
<Button size="tag" style="ghost" outline onclick={editPatch}>

View File

@ -97,10 +97,10 @@ export class BranchController {
}
/*
* Creates a new GitButler reference associated with a branch.
* Creates a new GitButler change reference associated with a branch.
* @param branchId
* @param reference in the format refs/remotes/origin/my-branch (must be remote)
* @param commitOid The commit oid to point the reference
* @param changeId The change id to point the reference to
*/
async createChangeReference(branchId: string, referenceName: string, changeId: string) {
try {
@ -115,6 +115,25 @@ 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 changeId The change id that is being pushed
*/
async pushChangeReference(branchId: string, referenceName: string, withForce: boolean = false) {
try {
await invoke<void>('push_change_reference', {
projectId: this.projectId,
branchId: branchId,
name: referenceName,
withForce: withForce
});
} catch (err) {
showError('Failed to push change reference', err);
}
}
async updateBranchRemoteName(branchId: string, upstream: string) {
try {
await invoke<void>('update_virtual_branch', {

View File

@ -369,6 +369,18 @@ impl VirtualBranchActions {
gitbutler_repo::create_change_reference(&ctx, branch_id, name, change_id)
}
pub fn push_change_reference(
&self,
project: &Project,
branch_id: BranchId,
name: ReferenceName,
with_force: bool,
) -> Result<()> {
let helper = Helper::default();
let ctx = open_with_verify(project)?;
gitbutler_repo::push_change_reference(&ctx, branch_id, name, with_force, &helper)
}
pub fn reorder_commit(
&self,
project: &Project,

View File

@ -172,6 +172,7 @@ fn main() {
virtual_branches::commands::undo_commit,
virtual_branches::commands::insert_blank_commit,
virtual_branches::commands::create_change_reference,
virtual_branches::commands::push_change_reference,
virtual_branches::commands::reorder_commit,
virtual_branches::commands::update_commit_message,
virtual_branches::commands::list_remote_branches,

View File

@ -412,6 +412,22 @@ pub mod commands {
Ok(())
}
#[tauri::command(async)]
#[instrument(skip(projects, windows), err(Debug))]
pub fn push_change_reference(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
name: ReferenceName,
with_force: bool,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
VirtualBranchActions.push_change_reference(&project, branch_id, name, with_force)?;
emit_vbranches(&windows, project_id);
Ok(())
}
#[tauri::command(async)]
#[instrument(skip(projects, windows), err(Debug))]
pub fn reorder_commit(