Merge pull request #4243 from gitbutlerapp/simplify-virtual-branches-controller-deps-graph

simplify virtual branches controller deps graph
This commit is contained in:
Kiril Videlov 2024-07-04 15:50:51 +02:00 committed by GitHub
commit ec52598f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 836 additions and 879 deletions

View File

@ -16,7 +16,7 @@ use super::{
}; };
use crate::{ use crate::{
git, project_repository, git, project_repository,
projects::{self, ProjectId}, projects::{self, Project},
}; };
#[derive(Clone)] #[derive(Clone)]
@ -39,14 +39,14 @@ impl Controller {
pub async fn create_commit( pub async fn create_commit(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
message: &str, message: &str,
ownership: Option<&BranchOwnershipClaims>, ownership: Option<&BranchOwnershipClaims>,
run_hooks: bool, run_hooks: bool,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let result = let result =
super::commit(project_repository, branch_id, message, ownership, run_hooks) super::commit(project_repository, branch_id, message, ownership, run_hooks)
@ -65,33 +65,32 @@ impl Controller {
pub async fn can_apply_remote_branch( pub async fn can_apply_remote_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch_name: &git::RemoteRefname, branch_name: &git::RemoteRefname,
) -> Result<bool> { ) -> Result<bool> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
super::is_remote_branch_mergeable(&project_repository, branch_name).map_err(Into::into) super::is_remote_branch_mergeable(&project_repository, branch_name).map_err(Into::into)
} }
pub async fn list_virtual_branches( pub async fn list_virtual_branches(
&self, &self,
project_id: ProjectId, project: &Project,
) -> Result<(Vec<super::VirtualBranch>, Vec<git::diff::FileDiff>)> { ) -> Result<(Vec<super::VirtualBranch>, Vec<git::diff::FileDiff>)> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
super::list_virtual_branches(project_repository).map_err(Into::into) super::list_virtual_branches(project_repository).map_err(Into::into)
}) })
} }
pub async fn create_virtual_branch( pub async fn create_virtual_branch(
&self, &self,
project_id: ProjectId, project: &Project,
create: &super::branch::BranchCreateRequest, create: &super::branch::BranchCreateRequest,
) -> Result<BranchId> { ) -> Result<BranchId> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let branch_id = super::create_virtual_branch(project_repository, create)?.id; let branch_id = super::create_virtual_branch(project_repository, create)?.id;
Ok(branch_id) Ok(branch_id)
}) })
@ -99,63 +98,55 @@ impl Controller {
pub async fn create_virtual_branch_from_branch( pub async fn create_virtual_branch_from_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch: &git::Refname, branch: &git::Refname,
) -> Result<BranchId> { ) -> Result<BranchId> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
super::create_virtual_branch_from_branch(project_repository, branch).map_err(Into::into) super::create_virtual_branch_from_branch(project_repository, branch).map_err(Into::into)
}) })
} }
pub async fn get_base_branch_data(&self, project_id: ProjectId) -> Result<BaseBranch> { pub async fn get_base_branch_data(&self, project: &Project) -> Result<BaseBranch> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
super::get_base_branch_data(&project_repository) super::get_base_branch_data(&project_repository)
} }
pub async fn list_remote_commit_files( pub async fn list_remote_commit_files(
&self, &self,
project_id: ProjectId, project: &Project,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<Vec<RemoteBranchFile>> { ) -> Result<Vec<RemoteBranchFile>> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
super::list_remote_commit_files(project_repository.repo(), commit_oid).map_err(Into::into) super::list_remote_commit_files(project_repository.repo(), commit_oid).map_err(Into::into)
} }
pub async fn set_base_branch( pub async fn set_base_branch(
&self, &self,
project_id: ProjectId, project: &Project,
target_branch: &git::RemoteRefname, target_branch: &git::RemoteRefname,
) -> Result<BaseBranch> { ) -> Result<BaseBranch> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::SetBaseBranch)); .create_snapshot(SnapshotDetails::new(OperationKind::SetBaseBranch));
super::set_base_branch(&project_repository, target_branch) super::set_base_branch(&project_repository, target_branch)
} }
pub async fn set_target_push_remote( pub async fn set_target_push_remote(&self, project: &Project, push_remote: &str) -> Result<()> {
&self, let project_repository = project_repository::Repository::open(project)?;
project_id: ProjectId,
push_remote: &str,
) -> Result<()> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?;
super::set_target_push_remote(&project_repository, push_remote) super::set_target_push_remote(&project_repository, push_remote)
} }
pub async fn integrate_upstream_commits( pub async fn integrate_upstream_commits(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::MergeUpstream)); .create_snapshot(SnapshotDetails::new(OperationKind::MergeUpstream));
@ -163,10 +154,10 @@ impl Controller {
}) })
} }
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<Vec<ReferenceName>> { pub async fn update_base_branch(&self, project: &Project) -> Result<Vec<ReferenceName>> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateWorkspaceBase)); .create_snapshot(SnapshotDetails::new(OperationKind::UpdateWorkspaceBase));
@ -183,12 +174,12 @@ impl Controller {
pub async fn update_virtual_branch( pub async fn update_virtual_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch_update: super::branch::BranchUpdateRequest, branch_update: super::branch::BranchUpdateRequest,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let old_branch = project_repository let old_branch = project_repository
.project() .project()
@ -210,24 +201,24 @@ impl Controller {
} }
pub async fn delete_virtual_branch( pub async fn delete_virtual_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
super::delete_branch(project_repository, branch_id) super::delete_branch(project_repository, branch_id)
}) })
} }
pub async fn unapply_ownership( pub async fn unapply_ownership(
&self, &self,
project_id: ProjectId, project: &Project,
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardHunk)); .create_snapshot(SnapshotDetails::new(OperationKind::DiscardHunk));
@ -235,10 +226,10 @@ impl Controller {
}) })
} }
pub async fn reset_files(&self, project_id: ProjectId, files: &Vec<String>) -> Result<()> { pub async fn reset_files(&self, project: &Project, files: &Vec<String>) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardFile)); .create_snapshot(SnapshotDetails::new(OperationKind::DiscardFile));
@ -248,14 +239,14 @@ impl Controller {
pub async fn amend( pub async fn amend(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::AmendCommit)); .create_snapshot(SnapshotDetails::new(OperationKind::AmendCommit));
@ -265,7 +256,7 @@ impl Controller {
pub async fn move_commit_file( pub async fn move_commit_file(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
from_commit_oid: git2::Oid, from_commit_oid: git2::Oid,
to_commit_oid: git2::Oid, to_commit_oid: git2::Oid,
@ -273,7 +264,7 @@ impl Controller {
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommitFile)); .create_snapshot(SnapshotDetails::new(OperationKind::MoveCommitFile));
@ -290,13 +281,13 @@ impl Controller {
pub async fn undo_commit( pub async fn undo_commit(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let result: Result<()> = let result: Result<()> =
super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into); super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into);
@ -313,14 +304,14 @@ impl Controller {
pub async fn insert_blank_commit( pub async fn insert_blank_commit(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
offset: i32, offset: i32,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::InsertBlankCommit)); .create_snapshot(SnapshotDetails::new(OperationKind::InsertBlankCommit));
@ -331,14 +322,14 @@ impl Controller {
pub async fn reorder_commit( pub async fn reorder_commit(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
offset: i32, offset: i32,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::ReorderCommit)); .create_snapshot(SnapshotDetails::new(OperationKind::ReorderCommit));
@ -349,13 +340,13 @@ impl Controller {
pub async fn reset_virtual_branch( pub async fn reset_virtual_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
target_commit_oid: git2::Oid, target_commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::UndoCommit)); .create_snapshot(SnapshotDetails::new(OperationKind::UndoCommit));
@ -366,13 +357,13 @@ impl Controller {
pub async fn convert_to_real_branch( pub async fn convert_to_real_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
name_conflict_resolution: NameConflitResolution, name_conflict_resolution: NameConflitResolution,
) -> Result<ReferenceName> { ) -> Result<ReferenceName> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let result = super::convert_to_real_branch( let result = super::convert_to_real_branch(
project_repository, project_repository,
@ -391,47 +382,42 @@ impl Controller {
pub async fn push_virtual_branch( pub async fn push_virtual_branch(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
with_force: bool, with_force: bool,
askpass: Option<Option<BranchId>>, askpass: Option<Option<BranchId>>,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
let helper = self.helper.clone(); let helper = self.helper.clone();
self.with_verify_branch_async(project_id, move |project_repository| { self.with_verify_branch_async(project, move |project_repository| {
super::push(project_repository, branch_id, with_force, &helper, askpass) super::push(project_repository, branch_id, with_force, &helper, askpass)
})? })?
.await? .await?
} }
pub async fn list_remote_branches( pub async fn list_remote_branches(&self, project: Project) -> Result<Vec<super::RemoteBranch>> {
&self,
project_id: ProjectId,
) -> Result<Vec<super::RemoteBranch>> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?; let project_repository = project_repository::Repository::open(&project)?;
super::list_remote_branches(&project_repository) super::list_remote_branches(&project_repository)
} }
pub async fn get_remote_branch_data( pub async fn get_remote_branch_data(
&self, &self,
project_id: ProjectId, project: &Project,
refname: &git::Refname, refname: &git::Refname,
) -> Result<super::RemoteBranchData> { ) -> Result<super::RemoteBranchData> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
super::get_branch_data(&project_repository, refname) super::get_branch_data(&project_repository, refname)
} }
pub async fn squash( pub async fn squash(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::SquashCommit)); .create_snapshot(SnapshotDetails::new(OperationKind::SquashCommit));
@ -441,13 +427,13 @@ impl Controller {
pub async fn update_commit_message( pub async fn update_commit_message(
&self, &self,
project_id: ProjectId, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
message: &str, message: &str,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateCommitMessage)); .create_snapshot(SnapshotDetails::new(OperationKind::UpdateCommitMessage));
@ -458,11 +444,10 @@ impl Controller {
pub async fn fetch_from_remotes( pub async fn fetch_from_remotes(
&self, &self,
project_id: ProjectId, project: &Project,
askpass: Option<String>, askpass: Option<String>,
) -> Result<BaseBranch> { ) -> Result<BaseBranch> {
let project = self.projects.get(project_id)?; let mut project_repository = project_repository::Repository::open(project)?;
let mut project_repository = project_repository::Repository::open(&project)?;
let remotes = project_repository.remotes()?; let remotes = project_repository.remotes()?;
let fetch_results: Vec<Result<(), _>> = remotes let fetch_results: Vec<Result<(), _>> = remotes
@ -500,7 +485,7 @@ impl Controller {
let updated_project = self let updated_project = self
.projects .projects
.update(&projects::UpdateRequest { .update(&projects::UpdateRequest {
id: project_id, id: project.id,
project_data_last_fetched: Some(project_data_last_fetched), project_data_last_fetched: Some(project_data_last_fetched),
..Default::default() ..Default::default()
}) })
@ -517,13 +502,13 @@ impl Controller {
pub async fn move_commit( pub async fn move_commit(
&self, &self,
project_id: ProjectId, project: &Project,
target_branch_id: BranchId, target_branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
let _permit = self.semaphore.acquire().await; let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository| { self.with_verify_branch(project, |project_repository| {
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommit)); .create_snapshot(SnapshotDetails::new(OperationKind::MoveCommit));
@ -535,22 +520,20 @@ impl Controller {
impl Controller { impl Controller {
fn with_verify_branch<T>( fn with_verify_branch<T>(
&self, &self,
project_id: ProjectId, project: &Project,
action: impl FnOnce(&project_repository::Repository) -> Result<T>, action: impl FnOnce(&project_repository::Repository) -> Result<T>,
) -> Result<T> { ) -> Result<T> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
super::integration::verify_branch(&project_repository)?; super::integration::verify_branch(&project_repository)?;
action(&project_repository) action(&project_repository)
} }
fn with_verify_branch_async<T: Send + 'static>( fn with_verify_branch_async<T: Send + 'static>(
&self, &self,
project_id: ProjectId, project: &Project,
action: impl FnOnce(&project_repository::Repository) -> Result<T> + Send + 'static, action: impl FnOnce(&project_repository::Repository) -> Result<T> + Send + 'static,
) -> Result<JoinHandle<Result<T>>> { ) -> Result<JoinHandle<Result<T>>> {
let project = self.projects.get(project_id)?; let project_repository = project_repository::Repository::open(project)?;
let project_repository = project_repository::Repository::open(&project)?;
super::integration::verify_branch(&project_repository)?; super::integration::verify_branch(&project_repository)?;
Ok(tokio::task::spawn_blocking(move || { Ok(tokio::task::spawn_blocking(move || {
action(&project_repository) action(&project_repository)

View File

@ -5,6 +5,7 @@ async fn forcepush_allowed() {
let Test { let Test {
repository, repository,
project_id, project_id,
project,
controller, controller,
projects, projects,
.. ..
@ -19,7 +20,7 @@ async fn forcepush_allowed() {
.unwrap(); .unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -32,19 +33,19 @@ async fn forcepush_allowed() {
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_id = controller let commit_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -53,12 +54,12 @@ async fn forcepush_allowed() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller controller
.amend(*project_id, branch_id, commit_id, &to_amend) .amend(project, branch_id, commit_id, &to_amend)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -76,24 +77,24 @@ async fn forcepush_allowed() {
async fn forcepush_forbidden() { async fn forcepush_forbidden() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch_id, id: branch_id,
allow_rebasing: Some(false), allow_rebasing: Some(false),
@ -106,12 +107,12 @@ async fn forcepush_forbidden() {
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -120,7 +121,7 @@ async fn forcepush_forbidden() {
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
assert_eq!( assert_eq!(
controller controller
.amend(*project_id, branch_id, commit_oid, &to_amend) .amend(project, branch_id, commit_oid, &to_amend)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
@ -133,30 +134,30 @@ async fn forcepush_forbidden() {
async fn non_locked_hunk() { async fn non_locked_hunk() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -172,12 +173,12 @@ async fn non_locked_hunk() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller controller
.amend(*project_id, branch_id, commit_oid, &to_amend) .amend(project, branch_id, commit_oid, &to_amend)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -194,30 +195,30 @@ async fn non_locked_hunk() {
async fn locked_hunk() { async fn locked_hunk() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -237,12 +238,12 @@ async fn locked_hunk() {
fs::write(repository.path().join("file.txt"), "more content").unwrap(); fs::write(repository.path().join("file.txt"), "more content").unwrap();
let to_amend: branch::BranchOwnershipClaims = "file.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file.txt:1-2".parse().unwrap();
controller controller
.amend(*project_id, branch_id, commit_oid, &to_amend) .amend(project, branch_id, commit_oid, &to_amend)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -264,30 +265,30 @@ async fn locked_hunk() {
async fn non_existing_ownership() { async fn non_existing_ownership() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -303,7 +304,7 @@ async fn non_existing_ownership() {
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
assert_eq!( assert_eq!(
controller controller
.amend(*project_id, branch_id, commit_oid, &to_amend) .amend(project, branch_id, commit_oid, &to_amend)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),

View File

@ -4,7 +4,7 @@ use super::*;
async fn rebase_commit() { async fn rebase_commit() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -21,24 +21,24 @@ async fn rebase_commit() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let mut branch1_id = { let mut branch1_id = {
// create a branch with some commited work // create a branch with some commited work
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap(); fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "virtual commit", None, false) .create_commit(project, branch1_id, "virtual commit", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -51,7 +51,7 @@ async fn rebase_commit() {
let unapplied_branch = { let unapplied_branch = {
// unapply first vbranch // unapply first vbranch
let unapplied_branch = controller let unapplied_branch = controller
.convert_to_real_branch(*project_id, branch1_id, Default::default()) .convert_to_real_branch(project, branch1_id, Default::default())
.await .await
.unwrap(); .unwrap();
@ -64,7 +64,7 @@ async fn rebase_commit() {
"one" "one"
); );
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(&unapplied_branch).unwrap() git::Refname::from_str(&unapplied_branch).unwrap()
@ -72,10 +72,10 @@ async fn rebase_commit() {
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// branch is stil unapplied // branch is stil unapplied
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!( assert_eq!(
@ -91,12 +91,12 @@ async fn rebase_commit() {
{ {
// apply first vbranch again // apply first vbranch again
branch1_id = controller branch1_id = controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
// it should be rebased // it should be rebased
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
@ -120,7 +120,7 @@ async fn rebase_commit() {
async fn rebase_work() { async fn rebase_work() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -135,19 +135,19 @@ async fn rebase_work() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let mut branch1_id = { let mut branch1_id = {
// make a branch with some work // make a branch with some work
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("another_file.txt"), "").unwrap(); fs::write(repository.path().join("another_file.txt"), "").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -160,11 +160,11 @@ async fn rebase_work() {
let unapplied_branch = { let unapplied_branch = {
// unapply first vbranch // unapply first vbranch
let unapplied_branch = controller let unapplied_branch = controller
.convert_to_real_branch(*project_id, branch1_id, Default::default()) .convert_to_real_branch(project, branch1_id, Default::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert!(!repository.path().join("another_file.txt").exists()); assert!(!repository.path().join("another_file.txt").exists());
@ -175,10 +175,10 @@ async fn rebase_work() {
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// first branch is stil unapplied // first branch is stil unapplied
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert!(!repository.path().join("another_file.txt").exists()); assert!(!repository.path().join("another_file.txt").exists());
@ -188,12 +188,12 @@ async fn rebase_work() {
{ {
// apply first vbranch again // apply first vbranch again
branch1_id = controller branch1_id = controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
// workdir should be rebased, and work should be restored // workdir should be rebased, and work should be restored
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);

View File

@ -3,37 +3,37 @@ use super::*;
#[tokio::test] #[tokio::test]
async fn unapply_with_data() { async fn unapply_with_data() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
controller controller
.convert_to_real_branch(*project_id, branches[0].id, Default::default()) .convert_to_real_branch(project, branches[0].id, Default::default())
.await .await
.unwrap(); .unwrap();
assert!(!repository.path().join("file.txt").exists()); assert!(!repository.path().join("file.txt").exists());
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }
#[tokio::test] #[tokio::test]
async fn conflicting() { async fn conflicting() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
@ -50,7 +50,7 @@ async fn conflicting() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -59,7 +59,7 @@ async fn conflicting() {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap(); std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].base_current); assert!(branches[0].base_current);
assert!(branches[0].active); assert!(branches[0].active);
@ -69,7 +69,7 @@ async fn conflicting() {
); );
let unapplied_branch = controller let unapplied_branch = controller
.convert_to_real_branch(*project_id, branches[0].id, Default::default()) .convert_to_real_branch(project, branches[0].id, Default::default())
.await .await
.unwrap(); .unwrap();
@ -78,7 +78,7 @@ async fn conflicting() {
{ {
// update base branch, causing conflict // update base branch, causing conflict
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
assert_eq!( assert_eq!(
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(), std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
@ -89,7 +89,7 @@ async fn conflicting() {
let branch_id = { let branch_id = {
// apply branch, it should conflict // apply branch, it should conflict
let branch_id = controller let branch_id = controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
@ -98,7 +98,7 @@ async fn conflicting() {
"<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n" "<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n"
); );
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let branch = &branches[0]; let branch = &branches[0];
@ -115,7 +115,7 @@ async fn conflicting() {
{ {
// Converting the branch to a real branch should put us back in an unconflicted state // Converting the branch to a real branch should put us back in an unconflicted state
controller controller
.convert_to_real_branch(*project_id, branch_id, Default::default()) .convert_to_real_branch(project, branch_id, Default::default())
.await .await
.unwrap(); .unwrap();
@ -129,29 +129,29 @@ async fn conflicting() {
#[tokio::test] #[tokio::test]
async fn delete_if_empty() { async fn delete_if_empty() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
controller controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
controller controller
.convert_to_real_branch(*project_id, branches[0].id, Default::default()) .convert_to_real_branch(project, branches[0].id, Default::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }

View File

@ -8,19 +8,19 @@ use super::*;
#[tokio::test] #[tokio::test]
async fn should_lock_updated_hunks() { async fn should_lock_updated_hunks() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -28,7 +28,7 @@ async fn should_lock_updated_hunks() {
// by default, hunks are not locked // by default, hunks are not locked
repository.write_file("file.txt", &["content".to_string()]); repository.write_file("file.txt", &["content".to_string()]);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
@ -36,7 +36,7 @@ async fn should_lock_updated_hunks() {
} }
controller controller
.create_commit(*project_id, branch_id, "test", None, false) .create_commit(project, branch_id, "test", None, false)
.await .await
.unwrap(); .unwrap();
@ -45,7 +45,7 @@ async fn should_lock_updated_hunks() {
repository.write_file("file.txt", &["updated content".to_string()]); repository.write_file("file.txt", &["updated content".to_string()]);
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -62,7 +62,7 @@ async fn should_lock_updated_hunks() {
#[tokio::test] #[tokio::test]
async fn should_not_lock_disjointed_hunks() { async fn should_not_lock_disjointed_hunks() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
@ -74,12 +74,12 @@ async fn should_not_lock_disjointed_hunks() {
repository.push(); repository.push();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -87,7 +87,7 @@ async fn should_not_lock_disjointed_hunks() {
// new hunk in the middle of the file // new hunk in the middle of the file
lines[12] = "commited stuff".to_string(); lines[12] = "commited stuff".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
@ -95,11 +95,11 @@ async fn should_not_lock_disjointed_hunks() {
} }
controller controller
.create_commit(*project_id, branch_id, "test commit", None, false) .create_commit(project, branch_id, "test commit", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -108,7 +108,7 @@ async fn should_not_lock_disjointed_hunks() {
let mut changed_lines = lines.clone(); let mut changed_lines = lines.clone();
changed_lines[8] = "updated line".to_string(); changed_lines[8] = "updated line".to_string();
repository.write_file("file.txt", &changed_lines); repository.write_file("file.txt", &changed_lines);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
@ -121,7 +121,7 @@ async fn should_not_lock_disjointed_hunks() {
let mut changed_lines = lines.clone(); let mut changed_lines = lines.clone();
changed_lines[16] = "updated line".to_string(); changed_lines[16] = "updated line".to_string();
repository.write_file("file.txt", &changed_lines); repository.write_file("file.txt", &changed_lines);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
@ -134,7 +134,7 @@ async fn should_not_lock_disjointed_hunks() {
let mut changed_lines = lines.clone(); let mut changed_lines = lines.clone();
changed_lines[10] = "updated line".to_string(); changed_lines[10] = "updated line".to_string();
repository.write_file("file.txt", &changed_lines); repository.write_file("file.txt", &changed_lines);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
@ -148,7 +148,7 @@ async fn should_not_lock_disjointed_hunks() {
let mut changed_lines = lines.clone(); let mut changed_lines = lines.clone();
changed_lines[14] = "updated line".to_string(); changed_lines[14] = "updated line".to_string();
repository.write_file("file.txt", &changed_lines); repository.write_file("file.txt", &changed_lines);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
@ -162,7 +162,7 @@ async fn should_not_lock_disjointed_hunks() {
#[tokio::test] #[tokio::test]
async fn should_reset_into_same_branch() { async fn should_reset_into_same_branch() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
@ -172,18 +172,18 @@ async fn should_reset_into_same_branch() {
commit_and_push_initial(repository); commit_and_push_initial(repository);
let base_branch = controller let base_branch = controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
controller controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let branch_2_id = controller let branch_2_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
..Default::default() ..Default::default()
@ -196,11 +196,11 @@ async fn should_reset_into_same_branch() {
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
controller controller
.create_commit(*project_id, branch_2_id, "commit to branch 2", None, false) .create_commit(project, branch_2_id, "commit to branch 2", None, false)
.await .await
.unwrap(); .unwrap();
let files = get_virtual_branch(controller, *project_id, branch_2_id) let files = get_virtual_branch(controller, project, branch_2_id)
.await .await
.files; .files;
assert_eq!(files.len(), 0); assert_eq!(files.len(), 0);
@ -208,7 +208,7 @@ async fn should_reset_into_same_branch() {
// Set target to branch 1 and verify the file resets into branch 2. // Set target to branch 1 and verify the file resets into branch 2.
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch_2_id, id: branch_2_id,
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -219,11 +219,11 @@ async fn should_reset_into_same_branch() {
.unwrap(); .unwrap();
controller controller
.reset_virtual_branch(*project_id, branch_2_id, base_branch.base_sha) .reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
.await .await
.unwrap(); .unwrap();
let files = get_virtual_branch(controller, *project_id, branch_2_id) let files = get_virtual_branch(controller, project, branch_2_id)
.await .await
.files; .files;
assert_eq!(files.len(), 1); assert_eq!(files.len(), 1);
@ -232,7 +232,7 @@ async fn should_reset_into_same_branch() {
#[tokio::test] #[tokio::test]
async fn should_double_lock() { async fn should_double_lock() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
@ -243,12 +243,12 @@ async fn should_double_lock() {
commit_and_push_initial(repository); commit_and_push_initial(repository);
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -256,7 +256,7 @@ async fn should_double_lock() {
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let commit_1 = controller let commit_1 = controller
.create_commit(*project_id, branch_id, "commit 1", None, false) .create_commit(project, branch_id, "commit 1", None, false)
.await .await
.unwrap(); .unwrap();
@ -264,14 +264,14 @@ async fn should_double_lock() {
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let commit_2 = controller let commit_2 = controller
.create_commit(*project_id, branch_id, "commit 2", None, false) .create_commit(project, branch_id, "commit 2", None, false)
.await .await
.unwrap(); .unwrap();
lines[3] = "change3".to_string(); lines[3] = "change3".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let branch = get_virtual_branch(controller, *project_id, branch_id).await; let branch = get_virtual_branch(controller, project, branch_id).await;
let locks = &branch.files[0].hunks[0].locked_to.clone().unwrap(); let locks = &branch.files[0].hunks[0].locked_to.clone().unwrap();
assert_eq!(locks.len(), 2); assert_eq!(locks.len(), 2);
@ -286,11 +286,11 @@ fn commit_and_push_initial(repository: &TestProject) {
async fn get_virtual_branch( async fn get_virtual_branch(
controller: &Controller, controller: &Controller,
project_id: ProjectId, project: &Project,
branch_id: Id<Branch>, branch_id: Id<Branch>,
) -> VirtualBranch { ) -> VirtualBranch {
controller controller
.list_virtual_branches(project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0

View File

@ -4,13 +4,13 @@ use super::*;
async fn integration() { async fn integration() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -18,22 +18,22 @@ async fn integration() {
// make a remote branch // make a remote branch
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &super::branch::BranchCreateRequest::default()) .create_virtual_branch(project, &super::branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "first\n").unwrap(); std::fs::write(repository.path().join("file.txt"), "first\n").unwrap();
controller controller
.create_commit(*project_id, branch_id, "first", None, false) .create_commit(project, branch_id, "first", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -44,7 +44,7 @@ async fn integration() {
let name = branch.upstream.unwrap().name; let name = branch.upstream.unwrap().name;
controller controller
.delete_virtual_branch(*project_id, branch_id) .delete_virtual_branch(project, branch_id)
.await .await
.unwrap(); .unwrap();
@ -53,7 +53,7 @@ async fn integration() {
// checkout a existing remote branch // checkout a existing remote branch
let branch_id = controller let branch_id = controller
.create_virtual_branch_from_branch(*project_id, &branch_name) .create_virtual_branch_from_branch(project, &branch_name)
.await .await
.unwrap(); .unwrap();
@ -62,7 +62,7 @@ async fn integration() {
std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap(); std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
controller controller
.create_commit(*project_id, branch_id, "second", None, false) .create_commit(project, branch_id, "second", None, false)
.await .await
.unwrap(); .unwrap();
} }
@ -79,12 +79,12 @@ async fn integration() {
{ {
// merge branch into master // merge branch into master
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -102,13 +102,10 @@ async fn integration() {
{ {
// should mark commits as integrated // should mark commits as integrated
controller controller.fetch_from_remotes(project, None).await.unwrap();
.fetch_from_remotes(*project_id, None)
.await
.unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -127,7 +124,7 @@ async fn integration() {
async fn no_conflicts() { async fn no_conflicts() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -143,22 +140,19 @@ async fn no_conflicts() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
let branch_id = controller let branch_id = controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(project, &"refs/remotes/origin/branch".parse().unwrap())
*project_id,
&"refs/remotes/origin/branch".parse().unwrap(),
)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -169,7 +163,7 @@ async fn no_conflicts() {
async fn conflicts_with_uncommited() { async fn conflicts_with_uncommited() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -185,7 +179,7 @@ async fn conflicts_with_uncommited() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -193,21 +187,18 @@ async fn conflicts_with_uncommited() {
{ {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap(); std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
}; };
// branch should be created unapplied, because of the conflict // branch should be created unapplied, because of the conflict
let new_branch_id = controller let new_branch_id = controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(project, &"refs/remotes/origin/branch".parse().unwrap())
*project_id,
&"refs/remotes/origin/branch".parse().unwrap(),
)
.await .await
.unwrap(); .unwrap();
let new_branch = controller let new_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -223,7 +214,7 @@ async fn conflicts_with_uncommited() {
async fn conflicts_with_commited() { async fn conflicts_with_commited() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -239,7 +230,7 @@ async fn conflicts_with_commited() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -247,11 +238,11 @@ async fn conflicts_with_commited() {
{ {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap(); std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
controller controller
.create_commit(*project_id, branches[0].id, "hej", None, false) .create_commit(project, branches[0].id, "hej", None, false)
.await .await
.unwrap(); .unwrap();
}; };
@ -259,14 +250,11 @@ async fn conflicts_with_commited() {
// branch should be created unapplied, because of the conflict // branch should be created unapplied, because of the conflict
let new_branch_id = controller let new_branch_id = controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(project, &"refs/remotes/origin/branch".parse().unwrap())
*project_id,
&"refs/remotes/origin/branch".parse().unwrap(),
)
.await .await
.unwrap(); .unwrap();
let new_branch = controller let new_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -281,13 +269,13 @@ async fn conflicts_with_commited() {
#[tokio::test] #[tokio::test]
async fn from_default_target() { async fn from_default_target() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -296,7 +284,7 @@ async fn from_default_target() {
assert_eq!( assert_eq!(
controller controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(
*project_id, project,
&"refs/remotes/origin/master".parse().unwrap(), &"refs/remotes/origin/master".parse().unwrap(),
) )
.await .await
@ -309,13 +297,13 @@ async fn from_default_target() {
#[tokio::test] #[tokio::test]
async fn from_non_existent_branch() { async fn from_non_existent_branch() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -324,7 +312,7 @@ async fn from_non_existent_branch() {
assert_eq!( assert_eq!(
controller controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(
*project_id, project,
&"refs/remotes/origin/branch".parse().unwrap(), &"refs/remotes/origin/branch".parse().unwrap(),
) )
.await .await
@ -338,7 +326,7 @@ async fn from_non_existent_branch() {
async fn from_state_remote_branch() { async fn from_state_remote_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -359,19 +347,16 @@ async fn from_state_remote_branch() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(project, &"refs/remotes/origin/branch".parse().unwrap())
*project_id,
&"refs/remotes/origin/branch".parse().unwrap(),
)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);

View File

@ -3,28 +3,28 @@ use super::*;
#[tokio::test] #[tokio::test]
async fn should_unapply_diff() { async fn should_unapply_diff() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
// write some // write some
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
controller controller
.delete_virtual_branch(*project_id, branches[0].id) .delete_virtual_branch(project, branches[0].id)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert!(!repository.path().join("file.txt").exists()); assert!(!repository.path().join("file.txt").exists());
@ -39,20 +39,20 @@ async fn should_unapply_diff() {
#[tokio::test] #[tokio::test]
async fn should_remove_reference() { async fn should_remove_reference() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let id = controller let id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -61,12 +61,9 @@ async fn should_remove_reference() {
.await .await
.unwrap(); .unwrap();
controller controller.delete_virtual_branch(project, id).await.unwrap();
.delete_virtual_branch(*project_id, id)
.await
.unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
let refnames = repository let refnames = repository

View File

@ -3,37 +3,34 @@ use super::*;
#[tokio::test] #[tokio::test]
async fn should_update_last_fetched() { async fn should_update_last_fetched() {
let Test { let Test {
project_id, project,
projects,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let before_fetch = controller.get_base_branch_data(*project_id).await.unwrap(); let before_fetch = controller.get_base_branch_data(project).await.unwrap();
assert!(before_fetch.last_fetched_ms.is_none()); assert!(before_fetch.last_fetched_ms.is_none());
let fetch = controller let fetch = controller.fetch_from_remotes(project, None).await.unwrap();
.fetch_from_remotes(*project_id, None)
.await
.unwrap();
assert!(fetch.last_fetched_ms.is_some()); assert!(fetch.last_fetched_ms.is_some());
let after_fetch = controller.get_base_branch_data(*project_id).await.unwrap(); let project = &projects.get(project.id).unwrap();
let after_fetch = controller.get_base_branch_data(project).await.unwrap();
assert!(after_fetch.last_fetched_ms.is_some()); assert!(after_fetch.last_fetched_ms.is_some());
assert_eq!(fetch.last_fetched_ms, after_fetch.last_fetched_ms); assert_eq!(fetch.last_fetched_ms, after_fetch.last_fetched_ms);
let second_fetch = controller let second_fetch = controller.fetch_from_remotes(project, None).await.unwrap();
.fetch_from_remotes(*project_id, None)
.await
.unwrap();
assert!(second_fetch.last_fetched_ms.is_some()); assert!(second_fetch.last_fetched_ms.is_some());
assert_ne!(fetch.last_fetched_ms, second_fetch.last_fetched_ms); assert_ne!(fetch.last_fetched_ms, second_fetch.last_fetched_ms);
let after_second_fetch = controller.get_base_branch_data(*project_id).await.unwrap(); let project = &projects.get(project.id).unwrap();
let after_second_fetch = controller.get_base_branch_data(project).await.unwrap();
assert!(after_second_fetch.last_fetched_ms.is_some()); assert!(after_second_fetch.last_fetched_ms.is_some());
assert_eq!( assert_eq!(
second_fetch.last_fetched_ms, second_fetch.last_fetched_ms,

View File

@ -15,18 +15,18 @@ async fn twice() {
.add(test_project.path()) .add(test_project.path())
.expect("failed to add project"); .expect("failed to add project");
controller controller
.set_base_branch(project.id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
assert!(controller assert!(controller
.list_virtual_branches(project.id) .list_virtual_branches(&project)
.await .await
.unwrap() .unwrap()
.0 .0
.is_empty()); .is_empty());
projects.delete(project.id).await.unwrap(); projects.delete(project.id).await.unwrap();
controller controller
.list_virtual_branches(project.id) .list_virtual_branches(&project)
.await .await
.unwrap_err(); .unwrap_err();
} }
@ -34,13 +34,13 @@ async fn twice() {
{ {
let project = projects.add(test_project.path()).unwrap(); let project = projects.add(test_project.path()).unwrap();
controller controller
.set_base_branch(project.id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
// even though project is on gitbutler/integration, we should not import it // even though project is on gitbutler/integration, we should not import it
assert!(controller assert!(controller
.list_virtual_branches(project.id) .list_virtual_branches(&project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -54,7 +54,7 @@ async fn dirty_non_target() {
// that has uncommited changes. // that has uncommited changes.
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -64,11 +64,11 @@ async fn dirty_non_target() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1); assert_eq!(branches[0].files[0].hunks.len(), 1);
@ -82,7 +82,7 @@ async fn dirty_target() {
// that has uncommited changes. // that has uncommited changes.
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -90,11 +90,11 @@ async fn dirty_target() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1); assert_eq!(branches[0].files[0].hunks.len(), 1);
@ -106,7 +106,7 @@ async fn dirty_target() {
async fn commit_on_non_target_local() { async fn commit_on_non_target_local() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -116,11 +116,11 @@ async fn commit_on_non_target_local() {
repository.commit_all("commit on target"); repository.commit_all("commit on target");
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty()); assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -132,7 +132,7 @@ async fn commit_on_non_target_local() {
async fn commit_on_non_target_remote() { async fn commit_on_non_target_remote() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -143,11 +143,11 @@ async fn commit_on_non_target_remote() {
repository.push_branch(&"refs/heads/some-feature".parse().unwrap()); repository.push_branch(&"refs/heads/some-feature".parse().unwrap());
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty()); assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -159,7 +159,7 @@ async fn commit_on_non_target_remote() {
async fn commit_on_target() { async fn commit_on_target() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -168,11 +168,11 @@ async fn commit_on_target() {
repository.commit_all("commit on target"); repository.commit_all("commit on target");
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty()); assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -184,21 +184,21 @@ async fn commit_on_target() {
async fn submodule() { async fn submodule() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
let project = TestProject::default(); let test_project = TestProject::default();
let submodule_url: git::Url = project.path().display().to_string().parse().unwrap(); let submodule_url: git::Url = test_project.path().display().to_string().parse().unwrap();
repository.add_submodule(&submodule_url, path::Path::new("submodule")); repository.add_submodule(&submodule_url, path::Path::new("submodule"));
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1); assert_eq!(branches[0].files[0].hunks.len(), 1);

View File

@ -4,25 +4,25 @@ use super::*;
async fn insert_blank_commit_down() { async fn insert_blank_commit_down() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
@ -30,24 +30,24 @@ async fn insert_blank_commit_down() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let _commit3_id = controller let _commit3_id = controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.insert_blank_commit(*project_id, branch_id, commit2_id, 1) .insert_blank_commit(project, branch_id, commit2_id, 1)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -76,25 +76,25 @@ async fn insert_blank_commit_down() {
async fn insert_blank_commit_up() { async fn insert_blank_commit_up() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
@ -102,24 +102,24 @@ async fn insert_blank_commit_up() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let _commit3_id = controller let _commit3_id = controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.insert_blank_commit(*project_id, branch_id, commit2_id, -1) .insert_blank_commit(project, branch_id, commit2_id, -1)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0

View File

@ -89,7 +89,7 @@ mod verify_branch;
async fn resolve_conflict_flow() { async fn resolve_conflict_flow() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -107,19 +107,19 @@ async fn resolve_conflict_flow() {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
{ {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -127,11 +127,11 @@ async fn resolve_conflict_flow() {
let unapplied_branch = { let unapplied_branch = {
// fetch remote. There is now a conflict, so the branch will be unapplied // fetch remote. There is now a conflict, so the branch will be unapplied
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_branches = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// there is a conflict now, so the branch should be inactive // there is a conflict now, so the branch should be inactive
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(&unapplied_branches[0]).unwrap() git::Refname::from_str(&unapplied_branches[0]).unwrap()
@ -140,11 +140,11 @@ async fn resolve_conflict_flow() {
let branch1_id = { let branch1_id = {
// when we apply conflicted branch, it has conflict // when we apply conflicted branch, it has conflict
let branch1_id = controller let branch1_id = controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].active); assert!(branches[0].active);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
@ -163,7 +163,7 @@ async fn resolve_conflict_flow() {
// can't commit conflicts // can't commit conflicts
assert!(matches!( assert!(matches!(
controller controller
.create_commit(*project_id, branch1_id, "commit conflicts", None, false) .create_commit(project, branch1_id, "commit conflicts", None, false)
.await .await
.unwrap_err() .unwrap_err()
.downcast_ref(), .downcast_ref(),
@ -174,16 +174,16 @@ async fn resolve_conflict_flow() {
{ {
// fixing the conflict removes conflicted mark // fixing the conflict removes conflicted mark
fs::write(repository.path().join("file.txt"), "resolved").unwrap(); fs::write(repository.path().join("file.txt"), "resolved").unwrap();
controller.list_virtual_branches(*project_id).await.unwrap(); controller.list_virtual_branches(project).await.unwrap();
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, branch1_id, "resolution", None, false) .create_commit(project, branch1_id, "resolution", None, false)
.await .await
.unwrap(); .unwrap();
let commit = repository.find_commit(commit_oid).unwrap(); let commit = repository.find_commit(commit_oid).unwrap();
assert_eq!(commit.parent_count(), 2); assert_eq!(commit.parent_count(), 2);
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);

View File

@ -6,25 +6,25 @@ use super::*;
async fn move_file_down() { async fn move_file_down() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit1_id = controller let commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
let commit1 = repository.find_commit(commit1_id).unwrap(); let commit1 = repository.find_commit(commit1_id).unwrap();
@ -33,7 +33,7 @@ async fn move_file_down() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
let commit2 = repository.find_commit(commit2_id).unwrap(); let commit2 = repository.find_commit(commit2_id).unwrap();
@ -41,12 +41,12 @@ async fn move_file_down() {
// amend another hunk // amend another hunk
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller controller
.move_commit_file(*project_id, branch_id, commit2_id, commit1_id, &to_amend) .move_commit_file(project, branch_id, commit2_id, commit1_id, &to_amend)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -70,18 +70,18 @@ async fn move_file_down() {
async fn move_file_up() { async fn move_file_up() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -89,26 +89,26 @@ async fn move_file_up() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let commit1_id = controller let commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
// amend another hunk // amend another hunk
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller controller
.move_commit_file(*project_id, branch_id, commit1_id, commit2_id, &to_amend) .move_commit_file(project, branch_id, commit1_id, commit2_id, &to_amend)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -135,19 +135,19 @@ async fn move_file_up_overlapping_hunks() {
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create bottom commit // create bottom commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
@ -155,7 +155,7 @@ async fn move_file_up_overlapping_hunks() {
fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap(); fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
@ -167,26 +167,26 @@ async fn move_file_up_overlapping_hunks() {
.unwrap(); .unwrap();
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let commit3_id = controller let commit3_id = controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap(); .unwrap();
// create top commit // create top commit
fs::write(repository.path().join("file5.txt"), "content5").unwrap(); fs::write(repository.path().join("file5.txt"), "content5").unwrap();
let _commit4_id = controller let _commit4_id = controller
.create_commit(*project_id, branch_id, "commit four", None, false) .create_commit(project, branch_id, "commit four", None, false)
.await .await
.unwrap(); .unwrap();
// move one line from middle commit two up to middle commit one // move one line from middle commit two up to middle commit one
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap(); let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap();
controller controller
.move_commit_file(*project_id, branch_id, commit2_id, commit3_id, &to_amend) .move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0

View File

@ -6,40 +6,40 @@ use crate::suite::virtual_branches::Test;
async fn no_diffs() { async fn no_diffs() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, source_branch_id, "commit", None, false) .create_commit(project, source_branch_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
controller controller
.move_commit(*project_id, target_branch_id, commit_oid) .move_commit(project, target_branch_id, commit_oid)
.await .await
.unwrap(); .unwrap();
let destination_branch = controller let destination_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -48,7 +48,7 @@ async fn no_diffs() {
.unwrap(); .unwrap();
let source_branch = controller let source_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -66,25 +66,25 @@ async fn no_diffs() {
async fn diffs_on_source_branch() { async fn diffs_on_source_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, source_branch_id, "commit", None, false) .create_commit(project, source_branch_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
@ -95,17 +95,17 @@ async fn diffs_on_source_branch() {
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
controller controller
.move_commit(*project_id, target_branch_id, commit_oid) .move_commit(project, target_branch_id, commit_oid)
.await .await
.unwrap(); .unwrap();
let destination_branch = controller let destination_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -114,7 +114,7 @@ async fn diffs_on_source_branch() {
.unwrap(); .unwrap();
let source_branch = controller let source_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -132,31 +132,31 @@ async fn diffs_on_source_branch() {
async fn diffs_on_target_branch() { async fn diffs_on_target_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, source_branch_id, "commit", None, false) .create_commit(project, source_branch_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
..Default::default() ..Default::default()
@ -172,12 +172,12 @@ async fn diffs_on_target_branch() {
.unwrap(); .unwrap();
controller controller
.move_commit(*project_id, target_branch_id, commit_oid) .move_commit(project, target_branch_id, commit_oid)
.await .await
.unwrap(); .unwrap();
let destination_branch = controller let destination_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -186,7 +186,7 @@ async fn diffs_on_target_branch() {
.unwrap(); .unwrap();
let source_branch = controller let source_branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -204,38 +204,38 @@ async fn diffs_on_target_branch() {
async fn locked_hunks_on_source_branch() { async fn locked_hunks_on_source_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, source_branch_id, "commit", None, false) .create_commit(project, source_branch_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "locked content").unwrap(); std::fs::write(repository.path().join("file.txt"), "locked content").unwrap();
let target_branch_id = controller let target_branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
controller controller
.move_commit(*project_id, target_branch_id, commit_oid) .move_commit(project, target_branch_id, commit_oid)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
@ -247,30 +247,30 @@ async fn locked_hunks_on_source_branch() {
async fn no_commit() { async fn no_commit() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
controller controller
.create_commit(*project_id, source_branch_id, "commit", None, false) .create_commit(project, source_branch_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -278,7 +278,7 @@ async fn no_commit() {
assert_eq!( assert_eq!(
controller controller
.move_commit( .move_commit(
*project_id, project,
target_branch_id, target_branch_id,
git2::Oid::from_str(commit_id_hex).unwrap() git2::Oid::from_str(commit_id_hex).unwrap()
) )
@ -293,32 +293,32 @@ async fn no_commit() {
async fn no_branch() { async fn no_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid = controller
.create_commit(*project_id, source_branch_id, "commit", None, false) .create_commit(project, source_branch_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let id = BranchId::generate(); let id = BranchId::generate();
assert_eq!( assert_eq!(
controller controller
.move_commit(*project_id, id, commit_oid) .move_commit(project, id, commit_oid)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),

View File

@ -9,14 +9,13 @@ async fn workdir_vbranch_restore() -> anyhow::Result<()> {
let test = Test::default(); let test = Test::default();
let Test { let Test {
repository, repository,
project_id,
controller, controller,
project, project,
.. ..
} = &test; } = &test;
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -29,7 +28,7 @@ async fn workdir_vbranch_restore() -> anyhow::Result<()> {
)?; )?;
let branch_id = controller let branch_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some(round.to_string()), name: Some(round.to_string()),
..Default::default() ..Default::default()
@ -38,7 +37,7 @@ async fn workdir_vbranch_restore() -> anyhow::Result<()> {
.await?; .await?;
controller controller
.create_commit( .create_commit(
*project_id, project,
branch_id, branch_id,
&format!("commit {round}"), &format!("commit {round}"),
None, None,
@ -56,7 +55,7 @@ async fn workdir_vbranch_restore() -> anyhow::Result<()> {
); );
} }
let _empty = controller let _empty = controller
.create_virtual_branch(*project_id, &Default::default()) .create_virtual_branch(project, &Default::default())
.await?; .await?;
let snapshots = project.list_snapshots(10, None)?; let snapshots = project.list_snapshots(10, None)?;
@ -102,24 +101,23 @@ fn make_lines(count: usize) -> Vec<u8> {
async fn basic_oplog() -> anyhow::Result<()> { async fn basic_oplog() -> anyhow::Result<()> {
let Test { let Test {
repository, repository,
project_id,
controller, controller,
project, project,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse()?) .set_base_branch(project, &"refs/remotes/origin/master".parse()?)
.await?; .await?;
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await?; .await?;
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content")?; fs::write(repository.path().join("file.txt"), "content")?;
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await?; .await?;
// dont store large files // dont store large files
@ -135,7 +133,7 @@ async fn basic_oplog() -> anyhow::Result<()> {
fs::write(repository.path().join("file2.txt"), "content2")?; fs::write(repository.path().join("file2.txt"), "content2")?;
fs::write(repository.path().join("file3.txt"), "content3")?; fs::write(repository.path().join("file3.txt"), "content3")?;
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await?; .await?;
// Create conflict state // Create conflict state
@ -146,7 +144,7 @@ async fn basic_oplog() -> anyhow::Result<()> {
// create state with conflict state // create state with conflict state
let _empty_branch_id = controller let _empty_branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await?; .await?;
std::fs::remove_file(&base_merge_parent_path)?; std::fs::remove_file(&base_merge_parent_path)?;
@ -154,18 +152,18 @@ async fn basic_oplog() -> anyhow::Result<()> {
fs::write(repository.path().join("file4.txt"), "content4")?; fs::write(repository.path().join("file4.txt"), "content4")?;
let _commit3_id = controller let _commit3_id = controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await?; .await?;
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await? .await?
.0 .0
.into_iter() .into_iter()
.find(|b| b.id == branch_id) .find(|b| b.id == branch_id)
.unwrap(); .unwrap();
let branches = controller.list_virtual_branches(*project_id).await?; let branches = controller.list_virtual_branches(project).await?;
assert_eq!(branches.0.len(), 2); assert_eq!(branches.0.len(), 2);
assert_eq!(branch.commits.len(), 3); assert_eq!(branch.commits.len(), 3);
@ -204,7 +202,7 @@ async fn basic_oplog() -> anyhow::Result<()> {
project.restore_snapshot(snapshots[2].clone().commit_id)?; project.restore_snapshot(snapshots[2].clone().commit_id)?;
// the restore removed our new branch // the restore removed our new branch
let branches = controller.list_virtual_branches(*project_id).await?; let branches = controller.list_virtual_branches(project).await?;
assert_eq!(branches.0.len(), 1); assert_eq!(branches.0.len(), 1);
// assert that the conflicts file was removed // assert that the conflicts file was removed
@ -252,26 +250,25 @@ async fn basic_oplog() -> anyhow::Result<()> {
async fn restores_gitbutler_integration() -> anyhow::Result<()> { async fn restores_gitbutler_integration() -> anyhow::Result<()> {
let Test { let Test {
repository, repository,
project_id,
controller, controller,
project, project,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse()?) .set_base_branch(project, &"refs/remotes/origin/master".parse()?)
.await?; .await?;
assert_eq!(project.virtual_branches().list_branches()?.len(), 0); assert_eq!(project.virtual_branches().list_branches()?.len(), 0);
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await?; .await?;
assert_eq!(project.virtual_branches().list_branches()?.len(), 1); assert_eq!(project.virtual_branches().list_branches()?.len(), 1);
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content")?; fs::write(repository.path().join("file.txt"), "content")?;
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await?; .await?;
let repo = git2::Repository::open(&project.path)?; let repo = git2::Repository::open(&project.path)?;
@ -286,7 +283,7 @@ async fn restores_gitbutler_integration() -> anyhow::Result<()> {
// create second commit // create second commit
fs::write(repository.path().join("file.txt"), "changed content")?; fs::write(repository.path().join("file.txt"), "changed content")?;
let _commit2_id = controller let _commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await?; .await?;
// check the integration commit changed // check the integration commit changed
@ -365,18 +362,17 @@ async fn restores_gitbutler_integration() -> anyhow::Result<()> {
async fn head_corrupt_is_recreated_automatically() { async fn head_corrupt_is_recreated_automatically() {
let Test { let Test {
repository, repository,
project_id,
controller, controller,
project, project,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -396,7 +392,7 @@ async fn head_corrupt_is_recreated_automatically() {
.unwrap(); .unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.expect("the snapshot doesn't fail despite the corrupt head"); .expect("the snapshot doesn't fail despite the corrupt head");

View File

@ -6,23 +6,23 @@ mod create_virtual_branch {
#[tokio::test] #[tokio::test]
async fn simple() { async fn simple() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].name, "Virtual branch"); assert_eq!(branches[0].name, "Virtual branch");
@ -38,20 +38,20 @@ mod create_virtual_branch {
#[tokio::test] #[tokio::test]
async fn duplicate_name() { async fn duplicate_name() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&gitbutler_core::virtual_branches::branch::BranchCreateRequest { &gitbutler_core::virtual_branches::branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -62,7 +62,7 @@ mod create_virtual_branch {
let branch2_id = controller let branch2_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&gitbutler_core::virtual_branches::branch::BranchCreateRequest { &gitbutler_core::virtual_branches::branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -71,7 +71,7 @@ mod create_virtual_branch {
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 2); assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name"); assert_eq!(branches[0].name, "name");
@ -94,20 +94,20 @@ mod update_virtual_branch {
#[tokio::test] #[tokio::test]
async fn simple() { async fn simple() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -118,7 +118,7 @@ mod update_virtual_branch {
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch_id, id: branch_id,
name: Some("new name".to_string()), name: Some("new name".to_string()),
@ -128,7 +128,7 @@ mod update_virtual_branch {
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].name, "new name"); assert_eq!(branches[0].name, "new name");
@ -145,20 +145,20 @@ mod update_virtual_branch {
#[tokio::test] #[tokio::test]
async fn duplicate_name() { async fn duplicate_name() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -169,7 +169,7 @@ mod update_virtual_branch {
let branch2_id = controller let branch2_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
..Default::default() ..Default::default()
}, },
@ -179,7 +179,7 @@ mod update_virtual_branch {
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch2_id, id: branch2_id,
name: Some("name".to_string()), name: Some("name".to_string()),
@ -189,7 +189,7 @@ mod update_virtual_branch {
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 2); assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name"); assert_eq!(branches[0].name, "name");
@ -213,20 +213,20 @@ mod push_virtual_branch {
#[tokio::test] #[tokio::test]
async fn simple() { async fn simple() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -238,15 +238,15 @@ mod push_virtual_branch {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "test", None, false) .create_commit(project, branch1_id, "test", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch1_id, false, None) .push_virtual_branch(project, branch1_id, false, None)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name"); assert_eq!(branches[0].name, "name");
@ -266,14 +266,14 @@ mod push_virtual_branch {
#[tokio::test] #[tokio::test]
async fn duplicate_names() { async fn duplicate_names() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -281,7 +281,7 @@ mod push_virtual_branch {
// create and push branch with some work // create and push branch with some work
let branch1_id = controller let branch1_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -291,11 +291,11 @@ mod push_virtual_branch {
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "test", None, false) .create_commit(project, branch1_id, "test", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch1_id, false, None) .push_virtual_branch(project, branch1_id, false, None)
.await .await
.unwrap(); .unwrap();
branch1_id branch1_id
@ -304,7 +304,7 @@ mod push_virtual_branch {
// rename first branch // rename first branch
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch1_id, id: branch1_id,
name: Some("updated name".to_string()), name: Some("updated name".to_string()),
@ -318,7 +318,7 @@ mod push_virtual_branch {
// create another branch with first branch's old name and push it // create another branch with first branch's old name and push it
let branch2_id = controller let branch2_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
..Default::default() ..Default::default()
@ -328,17 +328,17 @@ mod push_virtual_branch {
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "updated content").unwrap(); fs::write(repository.path().join("file.txt"), "updated content").unwrap();
controller controller
.create_commit(*project_id, branch2_id, "test", None, false) .create_commit(project, branch2_id, "test", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch2_id, false, None) .push_virtual_branch(project, branch2_id, false, None)
.await .await
.unwrap(); .unwrap();
branch2_id branch2_id
}; };
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 2); assert_eq!(branches.len(), 2);
// first branch is pushing to old ref remotely // first branch is pushing to old ref remotely
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);

View File

@ -4,25 +4,25 @@ use super::*;
async fn reorder_commit_down() { async fn reorder_commit_down() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
@ -30,17 +30,17 @@ async fn reorder_commit_down() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.reorder_commit(*project_id, branch_id, commit2_id, 1) .reorder_commit(project, branch_id, commit2_id, 1)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -65,25 +65,25 @@ async fn reorder_commit_down() {
async fn reorder_commit_up() { async fn reorder_commit_up() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit1_id = controller let commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
@ -91,17 +91,17 @@ async fn reorder_commit_up() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let _commit2_id = controller let _commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.reorder_commit(*project_id, branch_id, commit1_id, -1) .reorder_commit(project, branch_id, commit1_id, -1)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0

View File

@ -8,18 +8,18 @@ use crate::suite::virtual_branches::Test;
async fn to_head() { async fn to_head() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -28,11 +28,11 @@ async fn to_head() {
// commit changes // commit changes
let oid = controller let oid = controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -49,11 +49,11 @@ async fn to_head() {
{ {
// reset changes to head // reset changes to head
controller controller
.reset_virtual_branch(*project_id, branch1_id, oid) .reset_virtual_branch(project, branch1_id, oid)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -70,18 +70,18 @@ async fn to_head() {
async fn to_target() { async fn to_target() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
let base_branch = controller let base_branch = controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -90,11 +90,11 @@ async fn to_target() {
// commit changes // commit changes
let oid = controller let oid = controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -109,11 +109,11 @@ async fn to_target() {
{ {
// reset changes to head // reset changes to head
controller controller
.reset_virtual_branch(*project_id, branch1_id, base_branch.base_sha) .reset_virtual_branch(project, branch1_id, base_branch.base_sha)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 0); assert_eq!(branches[0].commits.len(), 0);
@ -129,18 +129,18 @@ async fn to_target() {
async fn to_commit() { async fn to_commit() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -150,11 +150,11 @@ async fn to_commit() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let oid = controller let oid = controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -173,11 +173,11 @@ async fn to_commit() {
fs::write(repository.path().join("file.txt"), "more content").unwrap(); fs::write(repository.path().join("file.txt"), "more content").unwrap();
let second_commit_oid = controller let second_commit_oid = controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 2); assert_eq!(branches[0].commits.len(), 2);
@ -193,11 +193,11 @@ async fn to_commit() {
{ {
// reset changes to the first commit // reset changes to the first commit
controller controller
.reset_virtual_branch(*project_id, branch1_id, first_commit_oid) .reset_virtual_branch(project, branch1_id, first_commit_oid)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -214,18 +214,18 @@ async fn to_commit() {
async fn to_non_existing() { async fn to_non_existing() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -234,11 +234,11 @@ async fn to_non_existing() {
// commit changes // commit changes
let oid = controller let oid = controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -255,7 +255,7 @@ async fn to_non_existing() {
assert_eq!( assert_eq!(
controller controller
.reset_virtual_branch( .reset_virtual_branch(
*project_id, project,
branch1_id, branch1_id,
"fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap() "fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap()
) )

View File

@ -4,13 +4,13 @@ use super::*;
async fn unapplying_selected_branch_selects_anther() { async fn unapplying_selected_branch_selects_anther() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -18,17 +18,17 @@ async fn unapplying_selected_branch_selects_anther() {
// first branch should be created as default // first branch should be created as default
let b_id = controller let b_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// if default branch exists, new branch should not be created as default // if default branch exists, new branch should not be created as default
let b2_id = controller let b2_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
let b = branches.iter().find(|b| b.id == b_id).unwrap(); let b = branches.iter().find(|b| b.id == b_id).unwrap();
@ -38,11 +38,11 @@ async fn unapplying_selected_branch_selects_anther() {
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller controller
.convert_to_real_branch(*project_id, b_id, Default::default()) .convert_to_real_branch(project, b_id, Default::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, b2.id); assert_eq!(branches[0].id, b2.id);
@ -53,29 +53,29 @@ async fn unapplying_selected_branch_selects_anther() {
#[tokio::test] #[tokio::test]
async fn deleting_selected_branch_selects_anther() { async fn deleting_selected_branch_selects_anther() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
// first branch should be created as default // first branch should be created as default
let b_id = controller let b_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// if default branch exists, new branch should not be created as default // if default branch exists, new branch should not be created as default
let b2_id = controller let b2_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
let b = branches.iter().find(|b| b.id == b_id).unwrap(); let b = branches.iter().find(|b| b.id == b_id).unwrap();
@ -85,11 +85,11 @@ async fn deleting_selected_branch_selects_anther() {
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller controller
.delete_virtual_branch(*project_id, b_id) .delete_virtual_branch(project, b_id)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, b2.id); assert_eq!(branches[0].id, b2.id);
@ -99,23 +99,23 @@ async fn deleting_selected_branch_selects_anther() {
#[tokio::test] #[tokio::test]
async fn create_virtual_branch_should_set_selected_for_changes() { async fn create_virtual_branch_should_set_selected_for_changes() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
// first branch should be created as default // first branch should be created as default
let b_id = controller let b_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -126,11 +126,11 @@ async fn create_virtual_branch_should_set_selected_for_changes() {
// if default branch exists, new branch should not be created as default // if default branch exists, new branch should not be created as default
let b_id = controller let b_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -142,7 +142,7 @@ async fn create_virtual_branch_should_set_selected_for_changes() {
// explicitly don't make this one default // explicitly don't make this one default
let b_id = controller let b_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(false), selected_for_changes: Some(false),
..Default::default() ..Default::default()
@ -151,7 +151,7 @@ async fn create_virtual_branch_should_set_selected_for_changes() {
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -163,7 +163,7 @@ async fn create_virtual_branch_should_set_selected_for_changes() {
// explicitly make this one default // explicitly make this one default
let b_id = controller let b_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
..Default::default() ..Default::default()
@ -172,7 +172,7 @@ async fn create_virtual_branch_should_set_selected_for_changes() {
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -185,22 +185,22 @@ async fn create_virtual_branch_should_set_selected_for_changes() {
#[tokio::test] #[tokio::test]
async fn update_virtual_branch_should_reset_selected_for_changes() { async fn update_virtual_branch_should_reset_selected_for_changes() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let b1_id = controller let b1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let b1 = controller let b1 = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -210,11 +210,11 @@ async fn update_virtual_branch_should_reset_selected_for_changes() {
assert!(b1.selected_for_changes); assert!(b1.selected_for_changes);
let b2_id = controller let b2_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let b2 = controller let b2 = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -225,7 +225,7 @@ async fn update_virtual_branch_should_reset_selected_for_changes() {
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: b2_id, id: b2_id,
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -236,7 +236,7 @@ async fn update_virtual_branch_should_reset_selected_for_changes() {
.unwrap(); .unwrap();
let b1 = controller let b1 = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -246,7 +246,7 @@ async fn update_virtual_branch_should_reset_selected_for_changes() {
assert!(!b1.selected_for_changes); assert!(!b1.selected_for_changes);
let b2 = controller let b2 = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -260,24 +260,24 @@ async fn update_virtual_branch_should_reset_selected_for_changes() {
async fn unapply_virtual_branch_should_reset_selected_for_changes() { async fn unapply_virtual_branch_should_reset_selected_for_changes() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let b1_id = controller let b1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let b1 = controller let b1 = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -287,12 +287,12 @@ async fn unapply_virtual_branch_should_reset_selected_for_changes() {
assert!(b1.selected_for_changes); assert!(b1.selected_for_changes);
let b2_id = controller let b2_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let b2 = controller let b2 = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -302,12 +302,12 @@ async fn unapply_virtual_branch_should_reset_selected_for_changes() {
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller controller
.convert_to_real_branch(*project_id, b1_id, Default::default()) .convert_to_real_branch(project, b1_id, Default::default())
.await .await
.unwrap(); .unwrap();
assert!(controller assert!(controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -319,24 +319,24 @@ async fn unapply_virtual_branch_should_reset_selected_for_changes() {
async fn hunks_distribution() { async fn hunks_distribution() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
controller controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
..Default::default() ..Default::default()
@ -345,7 +345,7 @@ async fn hunks_distribution() {
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("another_file.txt"), "content").unwrap(); std::fs::write(repository.path().join("another_file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[1].files.len(), 1); assert_eq!(branches[1].files.len(), 1);
} }
@ -354,32 +354,32 @@ async fn hunks_distribution() {
async fn applying_first_branch() { async fn applying_first_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let unapplied_branch = controller let unapplied_branch = controller
.convert_to_real_branch(*project_id, branches[0].id, Default::default()) .convert_to_real_branch(project, branches[0].id, Default::default())
.await .await
.unwrap(); .unwrap();
let unapplied_branch = git::Refname::from_str(&unapplied_branch).unwrap(); let unapplied_branch = git::Refname::from_str(&unapplied_branch).unwrap();
controller controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].active); assert!(branches[0].active);
assert!(branches[0].selected_for_changes); assert!(branches[0].selected_for_changes);
@ -391,7 +391,7 @@ async fn applying_first_branch() {
async fn new_locked_hunk_without_modifying_existing() { async fn new_locked_hunk_without_modifying_existing() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -401,28 +401,28 @@ async fn new_locked_hunk_without_modifying_existing() {
repository.push(); repository.push();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
lines[0] = "modification 1".to_string(); lines[0] = "modification 1".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
controller controller
.create_commit(*project_id, branches[0].id, "second commit", None, false) .create_commit(project, branches[0].id, "second commit", None, false)
.await .await
.expect("failed to create commit"); .expect("failed to create commit");
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
controller controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
..Default::default() ..Default::default()
@ -434,13 +434,13 @@ async fn new_locked_hunk_without_modifying_existing() {
lines[8] = "modification 2".to_string(); lines[8] = "modification 2".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
assert_eq!(branches[1].files.len(), 1); assert_eq!(branches[1].files.len(), 1);
lines[0] = "modification 3".to_string(); lines[0] = "modification 3".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[1].files.len(), 1); assert_eq!(branches[1].files.len(), 1);
} }

View File

@ -3,13 +3,13 @@ use super::*;
#[tokio::test] #[tokio::test]
async fn success() { async fn success() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
} }
@ -20,7 +20,7 @@ mod error {
#[tokio::test] #[tokio::test]
async fn missing() { async fn missing() {
let Test { let Test {
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -28,7 +28,7 @@ mod error {
assert_eq!( assert_eq!(
controller controller
.set_base_branch( .set_base_branch(
*project_id, project,
&git::RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(), &git::RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
) )
.await .await
@ -48,7 +48,7 @@ mod go_back_to_integration {
async fn should_preserve_applied_vbranches() { async fn should_preserve_applied_vbranches() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -60,32 +60,32 @@ mod go_back_to_integration {
repository.push(); repository.push();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let vbranch_id = controller let vbranch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
std::fs::write(repository.path().join("another file.txt"), "content").unwrap(); std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
controller controller
.create_commit(*project_id, vbranch_id, "one", None, false) .create_commit(project, vbranch_id, "one", None, false)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, vbranch_id); assert_eq!(branches[0].id, vbranch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -95,7 +95,7 @@ mod go_back_to_integration {
async fn from_target_branch_index_conflicts() { async fn from_target_branch_index_conflicts() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -107,11 +107,11 @@ mod go_back_to_integration {
repository.push(); repository.push();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
@ -119,7 +119,7 @@ mod go_back_to_integration {
assert!(matches!( assert!(matches!(
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap_err() .unwrap_err()
.downcast_ref(), .downcast_ref(),
@ -131,7 +131,7 @@ mod go_back_to_integration {
async fn from_target_branch_with_uncommited() { async fn from_target_branch_with_uncommited() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -143,11 +143,11 @@ mod go_back_to_integration {
repository.push(); repository.push();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
@ -155,7 +155,7 @@ mod go_back_to_integration {
assert!(matches!( assert!(matches!(
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap_err() .unwrap_err()
.downcast_ref(), .downcast_ref(),
@ -167,7 +167,7 @@ mod go_back_to_integration {
async fn from_target_branch_with_commit() { async fn from_target_branch_with_commit() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -179,11 +179,11 @@ mod go_back_to_integration {
repository.push(); repository.push();
let base = controller let base = controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
@ -191,11 +191,11 @@ mod go_back_to_integration {
repository.commit_all("three"); repository.commit_all("three");
let base_two = controller let base_two = controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!(base_two, base); assert_eq!(base_two, base);
} }
@ -204,7 +204,7 @@ mod go_back_to_integration {
async fn from_target_branch_without_any_changes() { async fn from_target_branch_without_any_changes() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -216,21 +216,21 @@ mod go_back_to_integration {
repository.push(); repository.push();
let base = controller let base = controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
let base_two = controller let base_two = controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!(base_two, base); assert_eq!(base_two, base);
} }

View File

@ -4,25 +4,25 @@ use super::*;
async fn head() { async fn head() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -30,7 +30,7 @@ async fn head() {
{ {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -38,7 +38,7 @@ async fn head() {
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -46,18 +46,18 @@ async fn head() {
let commit_four_oid = { let commit_four_oid = {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit four", None, false) .create_commit(project, branch_id, "commit four", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.squash(*project_id, branch_id, commit_four_oid) .squash(project, branch_id, commit_four_oid)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -80,25 +80,25 @@ async fn head() {
async fn middle() { async fn middle() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -106,7 +106,7 @@ async fn middle() {
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -114,7 +114,7 @@ async fn middle() {
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -122,18 +122,18 @@ async fn middle() {
{ {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit four", None, false) .create_commit(project, branch_id, "commit four", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.squash(*project_id, branch_id, commit_two_oid) .squash(project, branch_id, commit_two_oid)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -157,6 +157,7 @@ async fn forcepush_allowed() {
let Test { let Test {
repository, repository,
project_id, project_id,
project,
controller, controller,
projects, projects,
.. ..
@ -171,32 +172,32 @@ async fn forcepush_allowed() {
.unwrap(); .unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -204,7 +205,7 @@ async fn forcepush_allowed() {
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -212,18 +213,18 @@ async fn forcepush_allowed() {
{ {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit four", None, false) .create_commit(project, branch_id, "commit four", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.squash(*project_id, branch_id, commit_two_oid) .squash(project, branch_id, commit_two_oid)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -247,24 +248,24 @@ async fn forcepush_allowed() {
async fn forcepush_forbidden() { async fn forcepush_forbidden() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch_id, id: branch_id,
allow_rebasing: Some(false), allow_rebasing: Some(false),
@ -277,20 +278,20 @@ async fn forcepush_forbidden() {
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -298,7 +299,7 @@ async fn forcepush_forbidden() {
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -306,14 +307,14 @@ async fn forcepush_forbidden() {
{ {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit four", None, false) .create_commit(project, branch_id, "commit four", None, false)
.await .await
.unwrap() .unwrap()
}; };
assert_eq!( assert_eq!(
controller controller
.squash(*project_id, branch_id, commit_two_oid) .squash(project, branch_id, commit_two_oid)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
@ -325,32 +326,32 @@ async fn forcepush_forbidden() {
async fn root_forbidden() { async fn root_forbidden() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
assert_eq!( assert_eq!(
controller controller
.squash(*project_id, branch_id, commit_one_oid) .squash(project, branch_id, commit_one_oid)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),

View File

@ -7,19 +7,19 @@ use crate::suite::virtual_branches::Test;
#[tokio::test] #[tokio::test]
async fn should_unapply_with_commits() { async fn should_unapply_with_commits() {
let Test { let Test {
project_id, project,
controller, controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -29,7 +29,7 @@ async fn should_unapply_with_commits() {
) )
.unwrap(); .unwrap();
controller controller
.create_commit(*project_id, branch_id, "test", None, false) .create_commit(project, branch_id, "test", None, false)
.await .await
.unwrap(); .unwrap();
@ -42,7 +42,7 @@ async fn should_unapply_with_commits() {
controller controller
.unapply_ownership( .unapply_ownership(
*project_id, project,
&"file.txt:1-5,7-11" &"file.txt:1-5,7-11"
.parse::<BranchOwnershipClaims>() .parse::<BranchOwnershipClaims>()
.unwrap(), .unwrap(),
@ -51,7 +51,7 @@ async fn should_unapply_with_commits() {
.unwrap_or_else(|err| panic!("{err:?}")); .unwrap_or_else(|err| panic!("{err:?}"));
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0

View File

@ -4,25 +4,25 @@ use super::*;
async fn undo_commit_simple() { async fn undo_commit_simple() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id = controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap(); .unwrap();
@ -30,24 +30,24 @@ async fn undo_commit_simple() {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let _commit3_id = controller let _commit3_id = controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.undo_commit(*project_id, branch_id, commit2_id) .undo_commit(project, branch_id, commit2_id)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0

View File

@ -8,7 +8,7 @@ mod applied_branch {
async fn conflicts_with_uncommitted_work() { async fn conflicts_with_uncommitted_work() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -24,14 +24,14 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
{ {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
controller controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -40,12 +40,12 @@ mod applied_branch {
let unapplied_branch = { let unapplied_branch = {
// fetch remote // fetch remote
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_branches = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should stash conflicting branch // should stash conflicting branch
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -54,10 +54,10 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -73,7 +73,7 @@ mod applied_branch {
async fn commited_conflict_not_pushed() { async fn commited_conflict_not_pushed() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -89,7 +89,7 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -97,25 +97,25 @@ mod applied_branch {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "conflicting commit", None, false) .create_commit(project, branch_id, "conflicting commit", None, false)
.await .await
.unwrap(); .unwrap();
} }
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_branches = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should stash the branch. // should stash the branch.
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -124,10 +124,10 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -144,7 +144,7 @@ mod applied_branch {
async fn commited_conflict_pushed() { async fn commited_conflict_pushed() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -160,7 +160,7 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -168,30 +168,30 @@ mod applied_branch {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "conflicting commit", None, false) .create_commit(project, branch_id, "conflicting commit", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
} }
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_branches = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should stash the branch. // should stash the branch.
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -200,10 +200,10 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -220,7 +220,7 @@ mod applied_branch {
async fn commited_conflict_not_pushed_fixed_with_more_work() { async fn commited_conflict_not_pushed_fixed_with_more_work() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -236,7 +236,7 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -244,13 +244,13 @@ mod applied_branch {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "conflicting commit", None, false) .create_commit(project, branch_id, "conflicting commit", None, false)
.await .await
.unwrap(); .unwrap();
@ -259,12 +259,12 @@ mod applied_branch {
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_branches = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should rebase upstream, and leave uncommited file as is // should rebase upstream, and leave uncommited file as is
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -273,10 +273,10 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -293,7 +293,7 @@ mod applied_branch {
async fn commited_conflict_pushed_fixed_with_more_work() { async fn commited_conflict_pushed_fixed_with_more_work() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -309,7 +309,7 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -317,13 +317,13 @@ mod applied_branch {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "conflicting commit", None, false) .create_commit(project, branch_id, "conflicting commit", None, false)
.await .await
.unwrap(); .unwrap();
@ -332,12 +332,12 @@ mod applied_branch {
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_branches = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should merge upstream, and leave uncommited file as is. // should merge upstream, and leave uncommited file as is.
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -346,10 +346,10 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller controller
.create_virtual_branch_from_branch(*project_id, &unapplied_branch) .create_virtual_branch_from_branch(project, &unapplied_branch)
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -369,6 +369,7 @@ mod applied_branch {
async fn force_push_ok() { async fn force_push_ok() {
let Test { let Test {
repository, repository,
project,
project_id, project_id,
controller, controller,
projects, projects,
@ -394,24 +395,24 @@ mod applied_branch {
.unwrap(); .unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "no conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "no conflicts", None, false) .create_commit(project, branch_id, "no conflicts", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -422,12 +423,12 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// rebases branch, since the branch is pushed and force pushing is // rebases branch, since the branch is pushed and force pushing is
// allowed // allowed
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -444,7 +445,7 @@ mod applied_branch {
async fn force_push_not_ok() { async fn force_push_not_ok() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -460,24 +461,24 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "no conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "no conflicts", None, false) .create_commit(project, branch_id, "no conflicts", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -488,7 +489,7 @@ mod applied_branch {
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch_id, id: branch_id,
allow_rebasing: Some(false), allow_rebasing: Some(false),
@ -500,11 +501,11 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// creates a merge commit, since the branch is pushed // creates a merge commit, since the branch is pushed
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -524,7 +525,7 @@ mod applied_branch {
async fn no_conflicts() { async fn no_conflicts() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -540,20 +541,20 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "no conflict").unwrap();
controller controller
.create_commit(*project_id, branch_id, "no conflicts", None, false) .create_commit(project, branch_id, "no conflicts", None, false)
.await .await
.unwrap(); .unwrap();
@ -564,11 +565,11 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// just rebases branch // just rebases branch
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -591,7 +592,7 @@ mod applied_branch {
async fn integrated_commit_plus_work() { async fn integrated_commit_plus_work() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -603,32 +604,32 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "second").unwrap(); fs::write(repository.path().join("file.txt"), "second").unwrap();
controller controller
.create_commit(*project_id, branch_id, "second", None, false) .create_commit(project, branch_id, "second", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
{ {
// merge branch upstream // merge branch upstream
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -647,11 +648,11 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// should remove integrated commit, but leave non integrated work as is // should remove integrated commit, but leave non integrated work as is
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -674,7 +675,7 @@ mod applied_branch {
async fn integrated_with_locked_conflicting_hunks() { async fn integrated_with_locked_conflicting_hunks() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -698,14 +699,14 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
// branch has no conflict // branch has no conflict
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -716,7 +717,7 @@ mod applied_branch {
.unwrap(); .unwrap();
controller controller
.create_commit(*project_id, branch_id, "fourth", None, false) .create_commit(project, branch_id, "fourth", None, false)
.await .await
.unwrap(); .unwrap();
@ -725,7 +726,7 @@ mod applied_branch {
// push the branch // push the branch
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -738,24 +739,19 @@ mod applied_branch {
{ {
// merge branch remotely // merge branch remotely
let branch = controller let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
.list_virtual_branches(*project_id)
.await
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
} }
repository.fetch(); repository.fetch();
let unapplied_refname = { let unapplied_refname = {
let unapplied_refnames = controller.update_base_branch(*project_id).await.unwrap(); let unapplied_refnames = controller.update_base_branch(project).await.unwrap();
assert_eq!(unapplied_refnames.len(), 1); assert_eq!(unapplied_refnames.len(), 1);
// removes integrated commit, leaves non commited work as is // removes integrated commit, leaves non commited work as is
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!( assert_eq!(
fs::read_to_string(repository.path().join("file.txt")).unwrap(), fs::read_to_string(repository.path().join("file.txt")).unwrap(),
@ -768,13 +764,13 @@ mod applied_branch {
{ {
controller controller
.create_virtual_branch_from_branch( .create_virtual_branch_from_branch(
*project_id, project,
&git::Refname::from_str(unapplied_refname.as_str()).unwrap(), &git::Refname::from_str(unapplied_refname.as_str()).unwrap(),
) )
.await .await
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].active); assert!(branches[0].active);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
@ -792,6 +788,7 @@ mod applied_branch {
async fn integrated_with_locked_hunks() { async fn integrated_with_locked_hunks() {
let Test { let Test {
repository, repository,
project,
project_id, project_id,
controller, controller,
projects, projects,
@ -807,20 +804,20 @@ mod applied_branch {
.unwrap(); .unwrap();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "first").unwrap(); fs::write(repository.path().join("file.txt"), "first").unwrap();
controller controller
.create_commit(*project_id, branch_id, "first", None, false) .create_commit(project, branch_id, "first", None, false)
.await .await
.unwrap(); .unwrap();
@ -828,7 +825,7 @@ mod applied_branch {
}; };
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -837,23 +834,18 @@ mod applied_branch {
{ {
// push and merge branch remotely // push and merge branch remotely
let branch = controller let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
.list_virtual_branches(*project_id)
.await
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
} }
repository.fetch(); repository.fetch();
{ {
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// removes integrated commit, leaves non commited work as is // removes integrated commit, leaves non commited work as is
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -867,27 +859,27 @@ mod applied_branch {
async fn integrated_with_non_locked_hunks() { async fn integrated_with_non_locked_hunks() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "first").unwrap(); fs::write(repository.path().join("file.txt"), "first").unwrap();
controller controller
.create_commit(*project_id, branch_id, "first", None, false) .create_commit(project, branch_id, "first", None, false)
.await .await
.unwrap(); .unwrap();
@ -895,7 +887,7 @@ mod applied_branch {
}; };
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -904,23 +896,18 @@ mod applied_branch {
{ {
// push and merge branch remotely // push and merge branch remotely
let branch = controller let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
.list_virtual_branches(*project_id)
.await
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
} }
repository.fetch(); repository.fetch();
{ {
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// removes integrated commit, leaves non commited work as is // removes integrated commit, leaves non commited work as is
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -934,7 +921,7 @@ mod applied_branch {
async fn all_integrated() { async fn all_integrated() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -950,32 +937,32 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
{ {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "second").unwrap(); fs::write(repository.path().join("file.txt"), "second").unwrap();
controller controller
.create_commit(*project_id, branch_id, "second", None, false) .create_commit(project, branch_id, "second", None, false)
.await .await
.unwrap(); .unwrap();
}; };
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// just removes integrated branch // just removes integrated branch
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }
} }
@ -984,7 +971,7 @@ mod applied_branch {
async fn integrate_work_while_being_behind() { async fn integrate_work_while_being_behind() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -1000,12 +987,12 @@ mod applied_branch {
} }
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -1013,33 +1000,28 @@ mod applied_branch {
// open pr // open pr
fs::write(repository.path().join("file2.txt"), "new file").unwrap(); fs::write(repository.path().join("file2.txt"), "new file").unwrap();
controller controller
.create_commit(*project_id, branch_id, "second", None, false) .create_commit(project, branch_id, "second", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
} }
{ {
// merge pr // merge pr
let branch = controller let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
.list_virtual_branches(*project_id)
.await
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
repository.fetch(); repository.fetch();
} }
{ {
// fetch remote // fetch remote
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// just removes integrated branch // just removes integrated branch
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }
} }
@ -1050,7 +1032,7 @@ mod applied_branch {
async fn should_not_get_confused_by_commits_in_other_branches() { async fn should_not_get_confused_by_commits_in_other_branches() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -1063,24 +1045,24 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_1_id = controller let branch_1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
fs::write(repository.path().join("file-3.txt"), "three").unwrap(); fs::write(repository.path().join("file-3.txt"), "three").unwrap();
controller controller
.create_commit(*project_id, branch_1_id, "third", None, false) .create_commit(project, branch_1_id, "third", None, false)
.await .await
.unwrap(); .unwrap();
let branch_2_id = controller let branch_2_id = controller
.create_virtual_branch( .create_virtual_branch(
*project_id, project,
&branch::BranchCreateRequest { &branch::BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
..Default::default() ..Default::default()
@ -1092,32 +1074,27 @@ mod applied_branch {
fs::write(repository.path().join("file-4.txt"), "four").unwrap(); fs::write(repository.path().join("file-4.txt"), "four").unwrap();
controller controller
.create_commit(*project_id, branch_2_id, "fourth", None, false) .create_commit(project, branch_2_id, "fourth", None, false)
.await .await
.unwrap(); .unwrap();
controller controller
.push_virtual_branch(*project_id, branch_2_id, false, None) .push_virtual_branch(project, branch_2_id, false, None)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller.list_virtual_branches(project).await.unwrap().0[1].clone();
.list_virtual_branches(*project_id)
.await
.unwrap()
.0[1]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
repository.fetch(); repository.fetch();
// TODO(mg): Figure out why test fails without listing first. // TODO(mg): Figure out why test fails without listing first.
controller.list_virtual_branches(*project_id).await.unwrap(); controller.list_virtual_branches(project).await.unwrap();
controller.update_base_branch(*project_id).await.unwrap(); controller.update_base_branch(project).await.unwrap();
// Verify we have only the first branch left, and that no files // Verify we have only the first branch left, and that no files
// are present. // are present.
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
} }

View File

@ -6,25 +6,25 @@ use super::*;
async fn head() { async fn head() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -32,7 +32,7 @@ async fn head() {
{ {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -40,7 +40,7 @@ async fn head() {
let commit_three_oid = { let commit_three_oid = {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -48,17 +48,12 @@ async fn head() {
let before_change_id = &commit_three.change_id(); let before_change_id = &commit_three.change_id();
controller controller
.update_commit_message( .update_commit_message(project, branch_id, commit_three_oid, "commit three updated")
*project_id,
branch_id,
commit_three_oid,
"commit three updated",
)
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -89,25 +84,25 @@ async fn head() {
async fn middle() { async fn middle() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -115,7 +110,7 @@ async fn middle() {
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -123,18 +118,18 @@ async fn middle() {
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.update_commit_message(*project_id, branch_id, commit_two_oid, "commit two updated") .update_commit_message(project, branch_id, commit_two_oid, "commit two updated")
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -158,13 +153,14 @@ async fn forcepush_allowed() {
let Test { let Test {
repository, repository,
project_id, project_id,
project,
controller, controller,
projects, projects,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
@ -177,30 +173,30 @@ async fn forcepush_allowed() {
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
controller controller
.update_commit_message(*project_id, branch_id, commit_one_oid, "commit one updated") .update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -221,24 +217,24 @@ async fn forcepush_allowed() {
async fn forcepush_forbidden() { async fn forcepush_forbidden() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
controller controller
.update_virtual_branch( .update_virtual_branch(
*project_id, project,
branch::BranchUpdateRequest { branch::BranchUpdateRequest {
id: branch_id, id: branch_id,
allow_rebasing: Some(false), allow_rebasing: Some(false),
@ -251,19 +247,19 @@ async fn forcepush_forbidden() {
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.push_virtual_branch(*project_id, branch_id, false, None) .push_virtual_branch(project, branch_id, false, None)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
controller controller
.update_commit_message(*project_id, branch_id, commit_one_oid, "commit one updated",) .update_commit_message(project, branch_id, commit_one_oid, "commit one updated",)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
@ -275,25 +271,25 @@ async fn forcepush_forbidden() {
async fn root() { async fn root() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -301,7 +297,7 @@ async fn root() {
{ {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit two", None, false) .create_commit(project, branch_id, "commit two", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -309,18 +305,18 @@ async fn root() {
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit three", None, false) .create_commit(project, branch_id, "commit three", None, false)
.await .await
.unwrap() .unwrap()
}; };
controller controller
.update_commit_message(*project_id, branch_id, commit_one_oid, "commit one updated") .update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
.await .await
.unwrap(); .unwrap();
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -343,32 +339,32 @@ async fn root() {
async fn empty() { async fn empty() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch_id = controller let branch_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller controller
.create_commit(*project_id, branch_id, "commit one", None, false) .create_commit(project, branch_id, "commit one", None, false)
.await .await
.unwrap() .unwrap()
}; };
assert_eq!( assert_eq!(
controller controller
.update_commit_message(*project_id, branch_id, commit_one_oid, "",) .update_commit_message(project, branch_id, commit_one_oid, "",)
.await .await
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),

View File

@ -4,18 +4,18 @@ use super::*;
async fn detect_upstream_commits() { async fn detect_upstream_commits() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -23,7 +23,7 @@ async fn detect_upstream_commits() {
// create first commit // create first commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -32,14 +32,14 @@ async fn detect_upstream_commits() {
// create second commit // create second commit
fs::write(repository.path().join("file.txt"), "content2").unwrap(); fs::write(repository.path().join("file.txt"), "content2").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap() .unwrap()
}; };
// push // push
controller controller
.push_virtual_branch(*project_id, branch1_id, false, None) .push_virtual_branch(project, branch1_id, false, None)
.await .await
.unwrap(); .unwrap();
@ -47,14 +47,14 @@ async fn detect_upstream_commits() {
// create third commit // create third commit
fs::write(repository.path().join("file.txt"), "content3").unwrap(); fs::write(repository.path().join("file.txt"), "content3").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap() .unwrap()
}; };
{ {
// should correctly detect pushed commits // should correctly detect pushed commits
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 3); assert_eq!(branches[0].commits.len(), 3);
@ -71,18 +71,18 @@ async fn detect_upstream_commits() {
async fn detect_integrated_commits() { async fn detect_integrated_commits() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
controller controller
.set_base_branch(*project_id, &"refs/remotes/origin/master".parse().unwrap()) .set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.await .await
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = controller
.create_virtual_branch(*project_id, &branch::BranchCreateRequest::default()) .create_virtual_branch(project, &branch::BranchCreateRequest::default())
.await .await
.unwrap(); .unwrap();
@ -90,7 +90,7 @@ async fn detect_integrated_commits() {
// create first commit // create first commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap() .unwrap()
}; };
@ -99,21 +99,21 @@ async fn detect_integrated_commits() {
// create second commit // create second commit
fs::write(repository.path().join("file.txt"), "content2").unwrap(); fs::write(repository.path().join("file.txt"), "content2").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap() .unwrap()
}; };
// push // push
controller controller
.push_virtual_branch(*project_id, branch1_id, false, None) .push_virtual_branch(project, branch1_id, false, None)
.await .await
.unwrap(); .unwrap();
{ {
// merge branch upstream // merge branch upstream
let branch = controller let branch = controller
.list_virtual_branches(*project_id) .list_virtual_branches(project)
.await .await
.unwrap() .unwrap()
.0 .0
@ -128,14 +128,14 @@ async fn detect_integrated_commits() {
// create third commit // create third commit
fs::write(repository.path().join("file.txt"), "content3").unwrap(); fs::write(repository.path().join("file.txt"), "content3").unwrap();
controller controller
.create_commit(*project_id, branch1_id, "commit", None, false) .create_commit(project, branch1_id, "commit", None, false)
.await .await
.unwrap() .unwrap()
}; };
{ {
// should correctly detect pushed commits // should correctly detect pushed commits
let (branches, _) = controller.list_virtual_branches(*project_id).await.unwrap(); let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 3); assert_eq!(branches[0].commits.len(), 3);

View File

@ -5,14 +5,14 @@ use super::*;
async fn should_fail_on_incorrect_branch() { async fn should_fail_on_incorrect_branch() {
let Test { let Test {
repository, repository,
project_id, project,
controller, controller,
.. ..
} = &Test::default(); } = &Test::default();
let branch_name: git::LocalRefname = "refs/heads/somebranch".parse().unwrap(); let branch_name: git::LocalRefname = "refs/heads/somebranch".parse().unwrap();
repository.checkout(&branch_name); repository.checkout(&branch_name);
let result = controller.list_virtual_branches(*project_id).await; let result = controller.list_virtual_branches(project).await;
let err = result.unwrap_err(); let err = result.unwrap_err();
assert_eq!( assert_eq!(

View File

@ -29,9 +29,10 @@ pub mod commands {
ownership: Option<BranchOwnershipClaims>, ownership: Option<BranchOwnershipClaims>,
run_hooks: bool, run_hooks: bool,
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let oid = handle let oid = handle
.state::<Controller>() .state::<Controller>()
.create_commit(project_id, branch, message, ownership.as_ref(), run_hooks) .create_commit(&project, branch, message, ownership.as_ref(), run_hooks)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(oid.to_string()) Ok(oid.to_string())
@ -43,9 +44,10 @@ pub mod commands {
handle: AppHandle, handle: AppHandle,
project_id: ProjectId, project_id: ProjectId,
) -> Result<VirtualBranches, Error> { ) -> Result<VirtualBranches, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let (branches, skipped_files) = handle let (branches, skipped_files) = handle
.state::<Controller>() .state::<Controller>()
.list_virtual_branches(project_id) .list_virtual_branches(&project)
.await?; .await?;
let proxy = handle.state::<assets::Proxy>(); let proxy = handle.state::<assets::Proxy>();
@ -63,9 +65,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
branch: branch::BranchCreateRequest, branch: branch::BranchCreateRequest,
) -> Result<BranchId, Error> { ) -> Result<BranchId, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_id = handle let branch_id = handle
.state::<Controller>() .state::<Controller>()
.create_virtual_branch(project_id, &branch) .create_virtual_branch(&project, &branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(branch_id) Ok(branch_id)
@ -78,9 +81,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
branch: git::Refname, branch: git::Refname,
) -> Result<BranchId, Error> { ) -> Result<BranchId, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_id = handle let branch_id = handle
.state::<Controller>() .state::<Controller>()
.create_virtual_branch_from_branch(project_id, &branch) .create_virtual_branch_from_branch(&project, &branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(branch_id) Ok(branch_id)
@ -93,9 +97,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
branch: BranchId, branch: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
handle handle
.state::<Controller>() .state::<Controller>()
.integrate_upstream_commits(project_id, branch) .integrate_upstream_commits(&project, branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -107,9 +112,10 @@ pub mod commands {
handle: AppHandle, handle: AppHandle,
project_id: ProjectId, project_id: ProjectId,
) -> Result<Option<BaseBranch>, Error> { ) -> Result<Option<BaseBranch>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
if let Ok(base_branch) = handle if let Ok(base_branch) = handle
.state::<Controller>() .state::<Controller>()
.get_base_branch_data(project_id) .get_base_branch_data(&project)
.await .await
{ {
let proxy = handle.state::<assets::Proxy>(); let proxy = handle.state::<assets::Proxy>();
@ -127,12 +133,13 @@ pub mod commands {
branch: &str, branch: &str,
push_remote: Option<&str>, // optional different name of a remote to push to (defaults to same as the branch) push_remote: Option<&str>, // optional different name of a remote to push to (defaults to same as the branch)
) -> Result<BaseBranch, Error> { ) -> Result<BaseBranch, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_name = format!("refs/remotes/{}", branch) let branch_name = format!("refs/remotes/{}", branch)
.parse() .parse()
.context("Invalid branch name")?; .context("Invalid branch name")?;
let base_branch = handle let base_branch = handle
.state::<Controller>() .state::<Controller>()
.set_base_branch(project_id, &branch_name) .set_base_branch(&project, &branch_name)
.await?; .await?;
let base_branch = handle let base_branch = handle
.state::<assets::Proxy>() .state::<assets::Proxy>()
@ -143,7 +150,7 @@ pub mod commands {
if let Some(push_remote) = push_remote { if let Some(push_remote) = push_remote {
handle handle
.state::<Controller>() .state::<Controller>()
.set_target_push_remote(project_id, push_remote) .set_target_push_remote(&project, push_remote)
.await?; .await?;
} }
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -156,9 +163,10 @@ pub mod commands {
handle: AppHandle, handle: AppHandle,
project_id: ProjectId, project_id: ProjectId,
) -> Result<Vec<ReferenceName>, Error> { ) -> Result<Vec<ReferenceName>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let unapplied_branches = handle let unapplied_branches = handle
.state::<Controller>() .state::<Controller>()
.update_base_branch(project_id) .update_base_branch(&project)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(unapplied_branches) Ok(unapplied_branches)
@ -171,9 +179,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
branch: branch::BranchUpdateRequest, branch: branch::BranchUpdateRequest,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
handle handle
.state::<Controller>() .state::<Controller>()
.update_virtual_branch(project_id, branch) .update_virtual_branch(&project, branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -187,9 +196,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
branch_id: BranchId, branch_id: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
handle handle
.state::<Controller>() .state::<Controller>()
.delete_virtual_branch(project_id, branch_id) .delete_virtual_branch(&project, branch_id)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -203,9 +213,10 @@ pub mod commands {
branch: BranchId, branch: BranchId,
name_conflict_resolution: NameConflitResolution, name_conflict_resolution: NameConflitResolution,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
handle handle
.state::<Controller>() .state::<Controller>()
.convert_to_real_branch(project_id, branch, name_conflict_resolution) .convert_to_real_branch(&project, branch, name_conflict_resolution)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -218,9 +229,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
ownership: BranchOwnershipClaims, ownership: BranchOwnershipClaims,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
handle handle
.state::<Controller>() .state::<Controller>()
.unapply_ownership(project_id, &ownership) .unapply_ownership(&project, &ownership)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -233,6 +245,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
files: &str, files: &str,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
// convert files to Vec<String> // convert files to Vec<String>
let files = files let files = files
.split('\n') .split('\n')
@ -240,7 +253,7 @@ pub mod commands {
.collect::<Vec<String>>(); .collect::<Vec<String>>();
handle handle
.state::<Controller>() .state::<Controller>()
.reset_files(project_id, &files) .reset_files(&project, &files)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -254,9 +267,10 @@ pub mod commands {
branch_id: BranchId, branch_id: BranchId,
with_force: bool, with_force: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
handle handle
.state::<Controller>() .state::<Controller>()
.push_virtual_branch(project_id, branch_id, with_force, Some(Some(branch_id))) .push_virtual_branch(&project, branch_id, with_force, Some(Some(branch_id)))
.await .await
.map_err(|err| err.context(Code::Unknown))?; .map_err(|err| err.context(Code::Unknown))?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -270,9 +284,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
branch: git::RemoteRefname, branch: git::RemoteRefname,
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
Ok(handle Ok(handle
.state::<Controller>() .state::<Controller>()
.can_apply_remote_branch(project_id, &branch) .can_apply_remote_branch(&project, &branch)
.await?) .await?)
} }
@ -283,10 +298,11 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
commit_oid: String, commit_oid: String,
) -> Result<Vec<RemoteBranchFile>, Error> { ) -> Result<Vec<RemoteBranchFile>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.list_remote_commit_files(project_id, commit_oid) .list_remote_commit_files(&project, commit_oid)
.await .await
.map_err(Into::into) .map_err(Into::into)
} }
@ -299,10 +315,11 @@ pub mod commands {
branch_id: BranchId, branch_id: BranchId,
target_commit_oid: String, target_commit_oid: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?; let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.reset_virtual_branch(project_id, branch_id, target_commit_oid) .reset_virtual_branch(&project, branch_id, target_commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -317,10 +334,11 @@ pub mod commands {
commit_oid: String, commit_oid: String,
ownership: BranchOwnershipClaims, ownership: BranchOwnershipClaims,
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
let oid = handle let oid = handle
.state::<Controller>() .state::<Controller>()
.amend(project_id, branch_id, commit_oid, &ownership) .amend(&project, branch_id, commit_oid, &ownership)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(oid.to_string()) Ok(oid.to_string())
@ -336,12 +354,13 @@ pub mod commands {
to_commit_oid: String, to_commit_oid: String,
ownership: BranchOwnershipClaims, ownership: BranchOwnershipClaims,
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?; let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?;
let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?; let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?;
let oid = handle let oid = handle
.state::<Controller>() .state::<Controller>()
.move_commit_file( .move_commit_file(
project_id, &project,
branch_id, branch_id,
from_commit_oid, from_commit_oid,
to_commit_oid, to_commit_oid,
@ -360,10 +379,11 @@ pub mod commands {
branch_id: BranchId, branch_id: BranchId,
commit_oid: String, commit_oid: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.undo_commit(project_id, branch_id, commit_oid) .undo_commit(&project, branch_id, commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -378,10 +398,11 @@ pub mod commands {
commit_oid: String, commit_oid: String,
offset: i32, offset: i32,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.insert_blank_commit(project_id, branch_id, commit_oid, offset) .insert_blank_commit(&project, branch_id, commit_oid, offset)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -396,10 +417,11 @@ pub mod commands {
commit_oid: String, commit_oid: String,
offset: i32, offset: i32,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.reorder_commit(project_id, branch_id, commit_oid, offset) .reorder_commit(&project, branch_id, commit_oid, offset)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -411,9 +433,10 @@ pub mod commands {
handle: tauri::AppHandle, handle: tauri::AppHandle,
project_id: ProjectId, project_id: ProjectId,
) -> Result<Vec<RemoteBranch>, Error> { ) -> Result<Vec<RemoteBranch>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let branches = handle let branches = handle
.state::<Controller>() .state::<Controller>()
.list_remote_branches(project_id) .list_remote_branches(project)
.await?; .await?;
Ok(branches) Ok(branches)
} }
@ -425,9 +448,10 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
refname: git::Refname, refname: git::Refname,
) -> Result<RemoteBranchData, Error> { ) -> Result<RemoteBranchData, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_data = handle let branch_data = handle
.state::<Controller>() .state::<Controller>()
.get_remote_branch_data(project_id, &refname) .get_remote_branch_data(&project, &refname)
.await?; .await?;
let branch_data = handle let branch_data = handle
.state::<assets::Proxy>() .state::<assets::Proxy>()
@ -444,10 +468,11 @@ pub mod commands {
branch_id: BranchId, branch_id: BranchId,
target_commit_oid: String, target_commit_oid: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?; let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.squash(project_id, branch_id, target_commit_oid) .squash(&project, branch_id, target_commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -460,10 +485,11 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
action: Option<String>, action: Option<String>,
) -> Result<BaseBranch, Error> { ) -> Result<BaseBranch, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let base_branch = handle let base_branch = handle
.state::<Controller>() .state::<Controller>()
.fetch_from_remotes( .fetch_from_remotes(
project_id, &project,
Some(action.unwrap_or_else(|| "unknown".to_string())), Some(action.unwrap_or_else(|| "unknown".to_string())),
) )
.await?; .await?;
@ -479,10 +505,11 @@ pub mod commands {
commit_oid: String, commit_oid: String,
target_branch_id: BranchId, target_branch_id: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.move_commit(project_id, target_branch_id, commit_oid) .move_commit(&project, target_branch_id, commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())
@ -497,10 +524,11 @@ pub mod commands {
commit_oid: String, commit_oid: String,
message: &str, message: &str,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle handle
.state::<Controller>() .state::<Controller>()
.update_commit_message(project_id, branch_id, commit_oid, message) .update_commit_message(&project, branch_id, commit_oid, message)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
Ok(()) Ok(())

View File

@ -85,15 +85,19 @@ impl Handler {
#[instrument(skip(self, project_id))] #[instrument(skip(self, project_id))]
async fn calculate_virtual_branches(&self, project_id: ProjectId) -> Result<()> { async fn calculate_virtual_branches(&self, project_id: ProjectId) -> Result<()> {
let project = self
.projects
.get(project_id)
.context("failed to get project")?;
match self match self
.vbranch_controller .vbranch_controller
.list_virtual_branches(project_id) .list_virtual_branches(&project)
.await .await
{ {
Ok((branches, skipped_files)) => { Ok((branches, skipped_files)) => {
let branches = self.assets_proxy.proxy_virtual_branches(branches).await; let branches = self.assets_proxy.proxy_virtual_branches(branches).await;
self.emit_app_event(Change::VirtualBranches { self.emit_app_event(Change::VirtualBranches {
project_id, project_id: project.id,
virtual_branches: VirtualBranches { virtual_branches: VirtualBranches {
branches, branches,
skipped_files, skipped_files,
@ -142,21 +146,13 @@ impl Handler {
Ok(()) Ok(())
} }
pub async fn git_file_change(
&self,
path: impl Into<PathBuf>,
project_id: ProjectId,
) -> Result<()> {
self.git_files_change(vec![path.into()], project_id).await
}
pub async fn git_files_change(&self, paths: Vec<PathBuf>, project_id: ProjectId) -> Result<()> { pub async fn git_files_change(&self, paths: Vec<PathBuf>, project_id: ProjectId) -> Result<()> {
let project = self let project = self
.projects .projects
.get(project_id) .get(project_id)
.context("failed to get project")?; .context("failed to get project")?;
let open_projects_repository = || { let open_projects_repository = || {
project_repository::Repository::open(&project) project_repository::Repository::open(&project.clone())
.context("failed to open project repository for project") .context("failed to open project repository for project")
}; };