diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 55c93841f..94a3915a0 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -8,7 +8,7 @@ use crate::{ bookmarks, database, deltas, events, files, gb_repository, project_repository::{self, activity}, projects, pty, reader, search, sessions, storage, users, - virtual_branches, + virtual_branches::{self, branch::{BranchUpdateRequest, Ownership}}, watcher, }; @@ -358,7 +358,7 @@ impl App { &self, project_id: &str, name: &str, - path: &str, + ownership: &Ownership, ) -> Result<()> { let gb_repository = self.gb_repository(project_id)?; @@ -369,7 +369,11 @@ impl App { let _permit = semaphore.acquire().await?; let branch_id = virtual_branches::create_virtual_branch(&gb_repository, name)?; - virtual_branches::move_files(&gb_repository, &branch_id, &vec![path.try_into()?])?; + virtual_branches::update_branch(&gb_repository, BranchUpdateRequest{ + id: branch_id, + name: None, + ownership: Some(ownership.clone()), + }).context("failed to update branch")?; Ok(()) } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 88288dd0b..f68cebd22 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -588,10 +588,10 @@ async fn create_virtual_branch( handle: tauri::AppHandle, project_id: &str, name: &str, - path: &str, + ownership: virtual_branches::branch::Ownership, ) -> Result<(), Error> { let app = handle.state::(); - app.create_virtual_branch(project_id, name, path) + app.create_virtual_branch(project_id, name, &ownership) .await .context("failed to create virtual branch")?; Ok(()) diff --git a/src/routes/repo/[projectId]/BranchLane.svelte b/src/routes/repo/[projectId]/BranchLane.svelte index 2a1b1e954..93c8c88c0 100644 --- a/src/routes/repo/[projectId]/BranchLane.svelte +++ b/src/routes/repo/[projectId]/BranchLane.svelte @@ -14,7 +14,9 @@ import { getExpandedWithCacheFallback, setExpandedWithCache } from './cache'; import type { VirtualBranchOperations } from './vbranches'; - const dispatch = createEventDispatcher(); + const dispatch = createEventDispatcher<{ + empty: {}; + }>(); export let branchId: string; export let name: string; @@ -48,7 +50,6 @@ }); files = fileItems.filter((file) => file.hunks && file.hunks.length > 0); - if (e.type == 'finalize' && files.length == 0) dispatch('empty'); if (e.type === 'finalize') updateBranchOwnership(); } @@ -57,21 +58,21 @@ .map((file) => file.id + ':' + file.hunks.map((hunk) => hunk.id.split(':')[1]).join(',')) .join('\n'); virtualBranches.updateBranchOwnership(branchId, ownership); + if (files.length == 0) dispatch('empty'); } function handleFileUpdate(fileId: string, hunks: Hunk[]) { const fileIndex = files.findIndex((f) => f.id == fileId); - console.log(fileIndex, fileId, hunks); if (fileIndex == -1) { return; } else { if (hunks.length === 0) { files.splice(fileIndex, 1); - if (files.length === 0) dispatch('empty'); } else { files[fileIndex].hunks = hunks; } files = files; + if (files.length === 0) dispatch('empty'); updateBranchOwnership(); } } diff --git a/src/routes/repo/[projectId]/NewBranchDropZone.svelte b/src/routes/repo/[projectId]/NewBranchDropZone.svelte index cb442094b..8f68ee1d5 100644 --- a/src/routes/repo/[projectId]/NewBranchDropZone.svelte +++ b/src/routes/repo/[projectId]/NewBranchDropZone.svelte @@ -23,8 +23,12 @@ branchItems.push(createBranch(file)); } + const ownership = branchItems[0].files + .map((file) => file.id + ':' + file.hunks.map((hunk) => hunk.id.split(':')[1]).join(',')) + .join('\n'); + if (e.type == 'finalize') { - virtualBranches.createBranch(branchItems[0].name, branchItems[0].files[0].path); + virtualBranches.createBranch(branchItems[0].name, ownership); items = []; return; } diff --git a/src/routes/repo/[projectId]/vbranches.ts b/src/routes/repo/[projectId]/vbranches.ts index fec01ee33..a0e1f7876 100644 --- a/src/routes/repo/[projectId]/vbranches.ts +++ b/src/routes/repo/[projectId]/vbranches.ts @@ -86,12 +86,12 @@ function createBranch( writable: Writable>, projectId: string, name: string, - path: string + ownership: string ) { return invoke('create_virtual_branch', { - projectId: projectId, - name: name, - path: path + projectId, + name, + ownership }).then(() => refresh(projectId, writable)); }