Update base branch button feature flagged

This commit is contained in:
Caleb Owens 2024-09-11 15:18:20 +02:00
parent 6e7aefd5c3
commit aeea013ba0
No known key found for this signature in database
4 changed files with 54 additions and 39 deletions

View File

@ -1,6 +1,8 @@
<script lang="ts"> <script lang="ts">
import Spacer from '../shared/Spacer.svelte'; import Spacer from '../shared/Spacer.svelte';
import { Project } from '$lib/backend/projects';
import CommitCard from '$lib/commit/CommitCard.svelte'; import CommitCard from '$lib/commit/CommitCard.svelte';
import UpdateBaseButton from '$lib/components/UpdateBaseButton.svelte';
import { projectMergeUpstreamWarningDismissed } from '$lib/config/config'; import { projectMergeUpstreamWarningDismissed } from '$lib/config/config';
import { getGitHost } from '$lib/gitHost/interface/gitHost'; import { getGitHost } from '$lib/gitHost/interface/gitHost';
import { ModeService } from '$lib/modes/service'; import { ModeService } from '$lib/modes/service';
@ -18,6 +20,7 @@
const branchController = getContext(BranchController); const branchController = getContext(BranchController);
const modeService = getContext(ModeService); const modeService = getContext(ModeService);
const gitHost = getGitHost(); const gitHost = getGitHost();
const project = getContext(Project);
const mode = modeService.mode; const mode = modeService.mode;
@ -36,6 +39,8 @@
showInfo('Stashed conflicting branches', infoText); showInfo('Stashed conflicting branches', infoText);
} }
} }
let updateBaseButton: UpdateBaseButton | undefined;
</script> </script>
<div class="wrapper"> <div class="wrapper">
@ -46,16 +51,21 @@
</div> </div>
{#if base.upstreamCommits?.length > 0} {#if base.upstreamCommits?.length > 0}
<UpdateBaseButton bind:this={updateBaseButton} showButton={false} />
<Button <Button
style="pop" style="pop"
kind="solid" kind="solid"
tooltip={`Merges the commits from ${base.branchName} into the base of all applied virtual branches`} tooltip={`Merges the commits from ${base.branchName} into the base of all applied virtual branches`}
disabled={$mode?.type !== 'OpenWorkspace'} disabled={$mode?.type !== 'OpenWorkspace'}
onclick={() => { onclick={() => {
if ($mergeUpstreamWarningDismissed) { if (project.succeedingRebases) {
updateBaseBranch(); updateBaseButton?.openModal();
} else { } else {
updateTargetModal.show(); if ($mergeUpstreamWarningDismissed) {
updateBaseBranch();
} else {
updateTargetModal.show();
}
} }
}} }}
> >

View File

@ -1,10 +1,13 @@
<script lang="ts"> <script lang="ts">
import { Project } from '$lib/backend/projects';
import { BaseBranchService } from '$lib/baseBranch/baseBranchService'; import { BaseBranchService } from '$lib/baseBranch/baseBranchService';
import CommitCard from '$lib/commit/CommitCard.svelte'; import CommitCard from '$lib/commit/CommitCard.svelte';
import { getGitHost } from '$lib/gitHost/interface/gitHost'; import { getGitHost } from '$lib/gitHost/interface/gitHost';
import { showInfo } from '$lib/notifications/toasts';
import Select from '$lib/select/Select.svelte'; import Select from '$lib/select/Select.svelte';
import SelectItem from '$lib/select/SelectItem.svelte'; import SelectItem from '$lib/select/SelectItem.svelte';
import { getContext } from '$lib/utils/context'; import { getContext } from '$lib/utils/context';
import { BranchController } from '$lib/vbranches/branchController';
import { VirtualBranch } from '$lib/vbranches/types'; import { VirtualBranch } from '$lib/vbranches/types';
import { import {
UpstreamIntegrationService, UpstreamIntegrationService,
@ -18,9 +21,17 @@
import { SvelteMap } from 'svelte/reactivity'; import { SvelteMap } from 'svelte/reactivity';
import type { Readable } from 'svelte/store'; import type { Readable } from 'svelte/store';
interface Props {
showButton?: boolean;
}
const { showButton = true }: Props = $props();
const upstreamIntegrationService = getContext(UpstreamIntegrationService); const upstreamIntegrationService = getContext(UpstreamIntegrationService);
const baseBranchService = getContext(BaseBranchService); const baseBranchService = getContext(BaseBranchService);
const gitHost = getGitHost(); const gitHost = getGitHost();
const branchController = getContext(BranchController);
const project = getContext(Project);
const base = baseBranchService.base; const base = baseBranchService.base;
@ -94,7 +105,7 @@
let integratingUpstream = $state<'inert' | 'loading' | 'complete'>('inert'); let integratingUpstream = $state<'inert' | 'loading' | 'complete'>('inert');
function openModal() { export function openModal() {
modalOpeningState = 'loading'; modalOpeningState = 'loading';
integratingUpstream = 'inert'; integratingUpstream = 'inert';
branchStatuses = upstreamIntegrationService.upstreamStatuses(); branchStatuses = upstreamIntegrationService.upstreamStatuses();
@ -107,10 +118,18 @@
async function integrate() { async function integrate() {
integratingUpstream = 'loading'; integratingUpstream = 'loading';
await upstreamIntegrationService.integrateUpstream([...results.values()]); await upstreamIntegrationService.integrateUpstream([...results.values()]);
await baseBranchService.refresh();
integratingUpstream = 'complete'; integratingUpstream = 'complete';
modal?.close(); modal?.close();
} }
async function updateBaseBranch() {
let infoText = await branchController.updateBaseBranch();
if (infoText) {
showInfo('Stashed conflicting branches', infoText);
}
}
</script> </script>
<Modal bind:this={modal} title="Integrate upstream changes" {onClose} width="small"> <Modal bind:this={modal} title="Integrate upstream changes" {onClose} width="small">
@ -179,16 +198,24 @@
{/snippet} {/snippet}
</Modal> </Modal>
<Button {#if showButton && ($base?.upstreamCommits.length || 0) > 0}
size="tag" <Button
style="error" size="tag"
kind="solid" style="error"
tooltip="Merge upstream into common base" kind="solid"
onclick={openModal} tooltip="Merge upstream into common base"
loading={modalOpeningState === 'loading'} onclick={() => {
> if (project.succeedingRebases) {
Update openModal();
</Button> } else {
updateBaseBranch();
}
}}
loading={modalOpeningState === 'loading'}
>
Update
</Button>
{/if}
<style> <style>
.upstream-commits { .upstream-commits {

View File

@ -484,7 +484,6 @@ mod test {
}; };
use gitbutler_branch::BranchOwnershipClaims; use gitbutler_branch::BranchOwnershipClaims;
use gitbutler_commit::commit_headers::HasCommitHeaders;
use tempfile::tempdir; use tempfile::tempdir;
use uuid::Uuid; use uuid::Uuid;
@ -620,21 +619,9 @@ mod test {
let tempdir = tempdir().unwrap(); let tempdir = tempdir().unwrap();
let repository = git2::Repository::init(tempdir.path()).unwrap(); let repository = git2::Repository::init(tempdir.path()).unwrap();
let initial_commit = commit_file(&repository, None, &[("foo.txt", "bar")]); let initial_commit = commit_file(&repository, None, &[("foo.txt", "bar")]);
let old_target = dbg!(commit_file( let old_target = commit_file(&repository, Some(&initial_commit), &[("foo.txt", "baz")]);
&repository, let branch_head = commit_file(&repository, Some(&old_target), &[("foo.txt", "fux")]);
Some(&initial_commit), let new_target = commit_file(&repository, Some(&old_target), &[("foo.txt", "qux")]);
&[("foo.txt", "baz")]
));
let branch_head = dbg!(commit_file(
&repository,
Some(&old_target),
&[("foo.txt", "fux")]
));
let new_target = dbg!(commit_file(
&repository,
Some(&old_target),
&[("foo.txt", "qux")]
));
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let branch = make_branch(branch_head.id(), branch_head.tree_id());
@ -674,14 +661,6 @@ mod test {
let head_commit = repository.find_commit(head).unwrap(); let head_commit = repository.find_commit(head).unwrap();
assert_eq!(head_commit.parent(0).unwrap().id(), new_target.id()); assert_eq!(head_commit.parent(0).unwrap().id(), new_target.id());
dbg!(&head_commit);
dbg!(head_commit.gitbutler_headers());
dbg!(head_commit
.tree()
.unwrap()
.into_iter()
.map(|entry| entry.clone().name().unwrap().to_owned())
.collect::<Vec<_>>());
assert!(head_commit.is_conflicted()); assert!(head_commit.is_conflicted());
let head_tree = repository let head_tree = repository

View File

@ -31,7 +31,6 @@ pub fn list_snapshots(
#[instrument(skip(projects), err(Debug))] #[instrument(skip(projects), err(Debug))]
pub fn restore_snapshot( pub fn restore_snapshot(
projects: State<'_, projects::Controller>, projects: State<'_, projects::Controller>,
handle: tauri::AppHandle,
project_id: ProjectId, project_id: ProjectId,
sha: String, sha: String,
) -> Result<(), Error> { ) -> Result<(), Error> {