mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 09:33:01 +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,
|
bookmarks, database, deltas, events, files, gb_repository,
|
||||||
project_repository::{self, activity},
|
project_repository::{self, activity},
|
||||||
projects, pty, reader, search, sessions, storage, users,
|
projects, pty, reader, search, sessions, storage, users,
|
||||||
virtual_branches,
|
virtual_branches::{self, branch::{BranchUpdateRequest, Ownership}},
|
||||||
watcher,
|
watcher,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ impl App {
|
|||||||
&self,
|
&self,
|
||||||
project_id: &str,
|
project_id: &str,
|
||||||
name: &str,
|
name: &str,
|
||||||
path: &str,
|
ownership: &Ownership,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let gb_repository = self.gb_repository(project_id)?;
|
let gb_repository = self.gb_repository(project_id)?;
|
||||||
|
|
||||||
@ -369,7 +369,11 @@ impl App {
|
|||||||
let _permit = semaphore.acquire().await?;
|
let _permit = semaphore.acquire().await?;
|
||||||
|
|
||||||
let branch_id = virtual_branches::create_virtual_branch(&gb_repository, name)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,10 +588,10 @@ async fn create_virtual_branch(
|
|||||||
handle: tauri::AppHandle,
|
handle: tauri::AppHandle,
|
||||||
project_id: &str,
|
project_id: &str,
|
||||||
name: &str,
|
name: &str,
|
||||||
path: &str,
|
ownership: virtual_branches::branch::Ownership,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let app = handle.state::<app::App>();
|
let app = handle.state::<app::App>();
|
||||||
app.create_virtual_branch(project_id, name, path)
|
app.create_virtual_branch(project_id, name, &ownership)
|
||||||
.await
|
.await
|
||||||
.context("failed to create virtual branch")?;
|
.context("failed to create virtual branch")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
import { getExpandedWithCacheFallback, setExpandedWithCache } from './cache';
|
import { getExpandedWithCacheFallback, setExpandedWithCache } from './cache';
|
||||||
import type { VirtualBranchOperations } from './vbranches';
|
import type { VirtualBranchOperations } from './vbranches';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<{
|
||||||
|
empty: {};
|
||||||
|
}>();
|
||||||
|
|
||||||
export let branchId: string;
|
export let branchId: string;
|
||||||
export let name: string;
|
export let name: string;
|
||||||
@ -48,7 +50,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
files = fileItems.filter((file) => file.hunks && file.hunks.length > 0);
|
files = fileItems.filter((file) => file.hunks && file.hunks.length > 0);
|
||||||
if (e.type == 'finalize' && files.length == 0) dispatch('empty');
|
|
||||||
if (e.type === 'finalize') updateBranchOwnership();
|
if (e.type === 'finalize') updateBranchOwnership();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,21 +58,21 @@
|
|||||||
.map((file) => file.id + ':' + file.hunks.map((hunk) => hunk.id.split(':')[1]).join(','))
|
.map((file) => file.id + ':' + file.hunks.map((hunk) => hunk.id.split(':')[1]).join(','))
|
||||||
.join('\n');
|
.join('\n');
|
||||||
virtualBranches.updateBranchOwnership(branchId, ownership);
|
virtualBranches.updateBranchOwnership(branchId, ownership);
|
||||||
|
if (files.length == 0) dispatch('empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFileUpdate(fileId: string, hunks: Hunk[]) {
|
function handleFileUpdate(fileId: string, hunks: Hunk[]) {
|
||||||
const fileIndex = files.findIndex((f) => f.id == fileId);
|
const fileIndex = files.findIndex((f) => f.id == fileId);
|
||||||
console.log(fileIndex, fileId, hunks);
|
|
||||||
if (fileIndex == -1) {
|
if (fileIndex == -1) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (hunks.length === 0) {
|
if (hunks.length === 0) {
|
||||||
files.splice(fileIndex, 1);
|
files.splice(fileIndex, 1);
|
||||||
if (files.length === 0) dispatch('empty');
|
|
||||||
} else {
|
} else {
|
||||||
files[fileIndex].hunks = hunks;
|
files[fileIndex].hunks = hunks;
|
||||||
}
|
}
|
||||||
files = files;
|
files = files;
|
||||||
|
if (files.length === 0) dispatch('empty');
|
||||||
updateBranchOwnership();
|
updateBranchOwnership();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,12 @@
|
|||||||
branchItems.push(createBranch(file));
|
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') {
|
if (e.type == 'finalize') {
|
||||||
virtualBranches.createBranch(branchItems[0].name, branchItems[0].files[0].path);
|
virtualBranches.createBranch(branchItems[0].name, ownership);
|
||||||
items = [];
|
items = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -86,12 +86,12 @@ function createBranch(
|
|||||||
writable: Writable<Loadable<Branch[]>>,
|
writable: Writable<Loadable<Branch[]>>,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
name: string,
|
name: string,
|
||||||
path: string
|
ownership: string
|
||||||
) {
|
) {
|
||||||
return invoke<object>('create_virtual_branch', {
|
return invoke<object>('create_virtual_branch', {
|
||||||
projectId: projectId,
|
projectId,
|
||||||
name: name,
|
name,
|
||||||
path: path
|
ownership
|
||||||
}).then(() => refresh(projectId, writable));
|
}).then(() => refresh(projectId, writable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user