Ability to push the base branch

If needed, the base branch can be pushed or force pushed
This commit is contained in:
estib 2024-09-13 15:39:28 +02:00
parent 2be4aaac2d
commit 9060a4287c
6 changed files with 49 additions and 1 deletions

View File

@ -67,6 +67,27 @@ export class BaseBranchService {
}); });
await this.fetchFromRemotes(); await this.fetchFromRemotes();
} }
async push(withForce?: boolean) {
this.loading.set(true);
try {
await invoke<void>('push_base_branch', {
projectId: this.projectId,
withForce
});
} catch (err: any) {
if (err.code === Code.DefaultTargetNotFound) {
// Swallow this error since user should be taken to project setup page
return;
} else if (err.code === Code.ProjectsGitAuth) {
showError('Failed to authenticate', err);
} else {
showError('Failed to push', err);
}
console.error(err);
}
await this.fetchFromRemotes();
}
} }
export async function getRemoteBranches( export async function getRemoteBranches(

View File

@ -158,6 +158,11 @@ pub fn set_target_push_remote(project: &Project, push_remote: &str) -> Result<()
base::set_target_push_remote(&ctx, push_remote) base::set_target_push_remote(&ctx, push_remote)
} }
pub fn push_base_branch(project: &Project, with_force: bool) -> Result<()> {
let ctx = CommandContext::open(project)?;
base::push(&ctx, with_force)
}
pub fn integrate_upstream_commits(project: &Project, branch_id: BranchId) -> Result<()> { pub fn integrate_upstream_commits(project: &Project, branch_id: BranchId) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)

View File

@ -647,3 +647,10 @@ pub(crate) fn target_to_base_branch(ctx: &CommandContext, target: &Target) -> Re
fn default_target(base_path: &Path) -> Result<Target> { fn default_target(base_path: &Path) -> Result<Target> {
VirtualBranchesHandle::new(base_path).get_default_target() VirtualBranchesHandle::new(base_path).get_default_target()
} }
pub(crate) fn push(ctx: &CommandContext, with_force: bool) -> Result<()> {
ctx.assure_resolved()?;
let target = default_target(&ctx.project().gb_dir())?;
let _ = ctx.push(target.sha, &target.branch, with_force, None, None);
Ok(())
}

View File

@ -8,7 +8,7 @@ pub use actions::{
get_uncommited_files_reusable, insert_blank_commit, integrate_upstream, get_uncommited_files_reusable, insert_blank_commit, integrate_upstream,
integrate_upstream_commits, list_local_branches, list_remote_commit_files, integrate_upstream_commits, list_local_branches, list_remote_commit_files,
list_virtual_branches, list_virtual_branches_cached, move_commit, move_commit_file, list_virtual_branches, list_virtual_branches_cached, move_commit, move_commit_file,
push_virtual_branch, reorder_commit, reset_files, reset_virtual_branch, push_base_branch, push_virtual_branch, reorder_commit, reset_files, reset_virtual_branch,
save_and_unapply_virutal_branch, set_base_branch, set_target_push_remote, squash, save_and_unapply_virutal_branch, set_base_branch, set_target_push_remote, squash,
unapply_ownership, unapply_without_saving_virtual_branch, undo_commit, update_base_branch, unapply_ownership, unapply_without_saving_virtual_branch, undo_commit, update_base_branch,
update_branch_order, update_commit_message, update_virtual_branch, update_branch_order, update_commit_message, update_virtual_branch,

View File

@ -159,6 +159,7 @@ fn main() {
virtual_branches::commands::get_base_branch_data, virtual_branches::commands::get_base_branch_data,
virtual_branches::commands::set_base_branch, virtual_branches::commands::set_base_branch,
virtual_branches::commands::update_base_branch, virtual_branches::commands::update_base_branch,
virtual_branches::commands::push_base_branch,
virtual_branches::commands::integrate_upstream_commits, virtual_branches::commands::integrate_upstream_commits,
virtual_branches::commands::update_virtual_branch, virtual_branches::commands::update_virtual_branch,
virtual_branches::commands::update_branch_order, virtual_branches::commands::update_branch_order,

View File

@ -174,6 +174,20 @@ pub mod commands {
Ok(unapplied_branches) Ok(unapplied_branches)
} }
#[tauri::command(async)]
#[instrument(skip(projects, windows), err(Debug))]
pub fn push_base_branch(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
with_force: bool,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
gitbutler_branch_actions::push_base_branch(&project, with_force)?;
emit_vbranches(&windows, project_id);
Ok(())
}
#[tauri::command(async)] #[tauri::command(async)]
#[instrument(skip(projects, windows), err(Debug))] #[instrument(skip(projects, windows), err(Debug))]
pub fn update_virtual_branch( pub fn update_virtual_branch(