mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 01:22:12 +03:00
create branch with ownership
This commit is contained in:
parent
b7c9940eb3
commit
785013d611
@ -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(())
|
||||
}
|
||||
|
||||
|
@ -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::App>();
|
||||
app.create_virtual_branch(project_id, name, path)
|
||||
app.create_virtual_branch(project_id, name, &ownership)
|
||||
.await
|
||||
.context("failed to create virtual branch")?;
|
||||
Ok(())
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -86,12 +86,12 @@ function createBranch(
|
||||
writable: Writable<Loadable<Branch[]>>,
|
||||
projectId: string,
|
||||
name: string,
|
||||
path: string
|
||||
ownership: string
|
||||
) {
|
||||
return invoke<object>('create_virtual_branch', {
|
||||
projectId: projectId,
|
||||
name: name,
|
||||
path: path
|
||||
projectId,
|
||||
name,
|
||||
ownership
|
||||
}).then(() => refresh(projectId, writable));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user