mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-01 12:26:02 +03:00
Merge pull request #3939 from gitbutlerapp/show-infobox-if-workspace-update-stashed-branches
show infobox if workspace update stashed branches
This commit is contained in:
commit
39e157fac6
@ -5,6 +5,7 @@
|
||||
import CommitCard from '$lib/components/CommitCard.svelte';
|
||||
import Modal from '$lib/components/Modal.svelte';
|
||||
import { projectMergeUpstreamWarningDismissed } from '$lib/config/config';
|
||||
import { showInfo } from '$lib/notifications/toasts';
|
||||
import { getContext } from '$lib/utils/context';
|
||||
import { tooltip } from '$lib/utils/tooltip';
|
||||
import { BranchController } from '$lib/vbranches/branchController';
|
||||
@ -22,6 +23,13 @@
|
||||
let mergeUpstreamWarningDismissedCheckbox = false;
|
||||
|
||||
$: multiple = base ? base.upstreamCommits.length > 1 || base.upstreamCommits.length == 0 : false;
|
||||
|
||||
async function updateBaseBranch() {
|
||||
let infoText = await branchController.updateBaseBranch();
|
||||
if (infoText) {
|
||||
showInfo('Stashed conflicting branches', infoText);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="wrapper">
|
||||
@ -38,7 +46,7 @@
|
||||
help={`Merges the commits from ${base.branchName} into the base of all applied virtual branches`}
|
||||
on:click={() => {
|
||||
if ($mergeUpstreamWarningDismissed) {
|
||||
branchController.updateBaseBranch();
|
||||
updateBaseBranch();
|
||||
} else {
|
||||
updateTargetModal.show();
|
||||
}
|
||||
@ -111,7 +119,7 @@
|
||||
style="pop"
|
||||
kind="solid"
|
||||
on:click={() => {
|
||||
branchController.updateBaseBranch();
|
||||
updateBaseBranch();
|
||||
if (mergeUpstreamWarningDismissedCheckbox) {
|
||||
mergeUpstreamWarningDismissed.set(true);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Tag from './Tag.svelte';
|
||||
import { showError } from '$lib/notifications/toasts';
|
||||
import { showInfo, showError } from '$lib/notifications/toasts';
|
||||
import { getContext } from '$lib/utils/context';
|
||||
import { BranchController } from '$lib/vbranches/branchController';
|
||||
|
||||
@ -17,7 +17,10 @@
|
||||
on:click={async () => {
|
||||
loading = true;
|
||||
try {
|
||||
await branchController.updateBaseBranch();
|
||||
let infoText = await branchController.updateBaseBranch();
|
||||
if (infoText) {
|
||||
showInfo('Stashed conflicting branches', infoText);
|
||||
}
|
||||
} catch (err) {
|
||||
showError('Failed update workspace', err);
|
||||
} finally {
|
||||
|
@ -26,6 +26,10 @@ export function showError(title: string, err: any) {
|
||||
showToast({ title, errorMessage: errorMessage, style: 'error' });
|
||||
}
|
||||
|
||||
export function showInfo(title: string, body: string) {
|
||||
showToast({ title, message: body, errorMessage: '', style: 'neutral' });
|
||||
}
|
||||
|
||||
export function dismissToast(messageId: string | undefined) {
|
||||
if (!messageId) return;
|
||||
toastStore.update((items) => items.filter((m) => m.id != messageId));
|
||||
|
@ -238,9 +238,18 @@ export class BranchController {
|
||||
}
|
||||
}
|
||||
|
||||
async updateBaseBranch() {
|
||||
async updateBaseBranch(): Promise<string | undefined> {
|
||||
try {
|
||||
await invoke<object>('update_base_branch', { projectId: this.projectId });
|
||||
const stashedConflicting = await invoke<Branch[]>('update_base_branch', {
|
||||
projectId: this.projectId
|
||||
});
|
||||
if (stashedConflicting.length > 0) {
|
||||
return `The following branches were stashed due to a merge conflict during updating the workspace: \n\n \
|
||||
${stashedConflicting.map((branch) => branch.name).join('\n')} \n\n \
|
||||
You can find them in the 'Branches' sidebar in order to resolve conflicts.`;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
} finally {
|
||||
this.targetBranchService.reload();
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ fn _print_tree(repo: &git2::Repository, tree: &git2::Tree) -> Result<()> {
|
||||
pub fn update_base_branch(
|
||||
project_repository: &project_repository::Repository,
|
||||
user: Option<&users::User>,
|
||||
) -> anyhow::Result<()> {
|
||||
) -> anyhow::Result<Vec<branch::Branch>> {
|
||||
if project_repository.is_resolving() {
|
||||
anyhow::bail!(errors::UpdateBaseBranchError::Conflict(
|
||||
errors::ProjectConflict {
|
||||
@ -356,8 +356,10 @@ pub fn update_base_branch(
|
||||
.peel_to_commit()
|
||||
.context(format!("failed to peel branch {} to commit", target.branch))?;
|
||||
|
||||
let mut unapplied_branches: Vec<branch::Branch> = Vec::new();
|
||||
|
||||
if new_target_commit.id() == target.sha.into() {
|
||||
return Ok(());
|
||||
return Ok(unapplied_branches);
|
||||
}
|
||||
|
||||
let new_target_tree = new_target_commit
|
||||
@ -433,6 +435,7 @@ pub fn update_base_branch(
|
||||
// branch tree conflicts with new target, unapply branch for now. we'll handle it later, when user applies it back.
|
||||
branch.applied = false;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
unapplied_branches.push(branch.clone());
|
||||
return Ok(Some(branch));
|
||||
}
|
||||
|
||||
@ -569,7 +572,7 @@ pub fn update_base_branch(
|
||||
|
||||
// Rewriting the integration commit is necessary after changing target sha.
|
||||
super::integration::update_gitbutler_integration(&vb_state, project_repository)?;
|
||||
Ok(())
|
||||
Ok(unapplied_branches)
|
||||
}
|
||||
|
||||
pub fn target_to_base_branch(
|
||||
|
@ -9,8 +9,8 @@ use tokio::{sync::Semaphore, task::JoinHandle};
|
||||
|
||||
use super::{
|
||||
branch::{BranchId, BranchOwnershipClaims},
|
||||
errors::{self},
|
||||
target, target_to_base_branch, BaseBranch, RemoteBranchFile, VirtualBranchesHandle,
|
||||
errors, target, target_to_base_branch, BaseBranch, Branch, RemoteBranchFile,
|
||||
VirtualBranchesHandle,
|
||||
};
|
||||
use crate::{
|
||||
git, project_repository,
|
||||
@ -164,7 +164,7 @@ impl Controller {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<(), Error> {
|
||||
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<Vec<Branch>, Error> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
.update_base_branch(project_id)
|
||||
@ -587,7 +587,7 @@ impl ControllerInner {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<(), Error> {
|
||||
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<Vec<Branch>, Error> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
self.with_verify_branch(project_id, |project_repository, user| {
|
||||
|
@ -150,13 +150,16 @@ pub mod commands {
|
||||
|
||||
#[tauri::command(async)]
|
||||
#[instrument(skip(handle), err(Debug))]
|
||||
pub async fn update_base_branch(handle: AppHandle, project_id: ProjectId) -> Result<(), Error> {
|
||||
handle
|
||||
pub async fn update_base_branch(
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
) -> Result<Vec<branch::Branch>, Error> {
|
||||
let unapplied_branches = handle
|
||||
.state::<Controller>()
|
||||
.update_base_branch(project_id)
|
||||
.await?;
|
||||
emit_vbranches(&handle, project_id).await;
|
||||
Ok(())
|
||||
Ok(unapplied_branches)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
|
@ -780,7 +780,7 @@ mod tests {
|
||||
|
||||
for (delay, events) in expected_events {
|
||||
MockClock::set_time(backup_time);
|
||||
state.queues = backup_queues.clone();
|
||||
state.queues.clone_from(&backup_queues);
|
||||
|
||||
match delay.as_str() {
|
||||
"none" => {}
|
||||
|
@ -192,7 +192,7 @@ mod utils {
|
||||
fn add_path(&mut self, path: &Path) {
|
||||
for (p, file_id) in &self.file_system {
|
||||
if p.starts_with(path) {
|
||||
self.paths.insert(p.clone(), file_id.clone());
|
||||
self.paths.insert(p.clone(), *file_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,7 +202,7 @@ mod utils {
|
||||
}
|
||||
|
||||
fn rescan(&mut self) {
|
||||
self.add_path(&Path::new("/"));
|
||||
self.add_path(Path::new("/"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user