only create branches if they have work

This commit is contained in:
Nikita Galaiko 2023-08-29 12:46:24 +02:00 committed by GitButler
parent 42fbd9cfd9
commit 710ab97b32
5 changed files with 16 additions and 14 deletions

View File

@ -94,7 +94,6 @@ async fn list_sessions(
let sessions = app
.list_sessions(project_id, earliest_timestamp_ms)
.with_context(|| format!("failed to list sessions for project {}", project_id))?;
dbg!(&sessions);
Ok(sessions)
}

View File

@ -9,7 +9,7 @@ use crate::{
reader, sessions,
};
use super::{branch, iterator, target};
use super::{branch, delete_branch, iterator, target};
pub fn get_base_branch_data(
gb_repository: &gb_repository::Repository,
@ -73,9 +73,6 @@ pub fn set_base_branch(
let target_writer = target::Writer::new(gb_repository);
target_writer.write_default(&target)?;
// if target.branch_name != head_name.branch() {
// if head is not pointing to the target branch, create initial virtual branch using the
// head
let current_session = gb_repository
.get_or_create_current_session()
.context("failed to get current session")?;
@ -93,14 +90,16 @@ pub fn set_base_branch(
.collect::<Vec<_>>();
if active_virtual_branches.is_empty() {
create_virtual_branch_from_branch(
let branch = create_virtual_branch_from_branch(
gb_repository,
project_repository,
&head_name,
Some(true),
)?;
if branch.ownership.is_empty() && branch.head == target.sha {
delete_branch(gb_repository, project_repository, &branch.id)?;
}
}
// }
set_exclude_decoration(project_repository)?;
@ -502,7 +501,7 @@ pub fn create_virtual_branch_from_branch(
project_repository: &project_repository::Repository,
upstream: &project_repository::branch::Name,
applied: Option<bool>,
) -> Result<String> {
) -> Result<branch::Branch> {
let current_session = gb_repository
.get_or_create_current_session()
.context("failed to get or create current session")?;
@ -612,5 +611,5 @@ pub fn create_virtual_branch_from_branch(
let writer = branch::Writer::new(gb_repository);
writer.write(&branch).context("failed to write branch")?;
Ok(branch_id)
Ok(branch)
}

View File

@ -47,6 +47,10 @@ impl FromStr for Ownership {
}
impl Ownership {
pub fn is_empty(&self) -> bool {
self.files.is_empty()
}
pub fn put(&mut self, ownership: &FileOwnership) {
let target = self
.files

View File

@ -113,7 +113,7 @@ impl Controller {
) -> Result<String, Error> {
self.with_lock::<Result<String, Error>>(project_id, || {
self.with_verify_branch(project_id, |gb_repository, project_repository| {
let branch_id = super::create_virtual_branch_from_branch(
let branch = super::create_virtual_branch_from_branch(
gb_repository,
project_repository,
branch,
@ -122,9 +122,9 @@ impl Controller {
.map_err(Error::Other)?;
// also apply the branch
super::apply_branch(gb_repository, project_repository, &branch_id)
super::apply_branch(gb_repository, project_repository, &branch.id)
.map_err(Error::Other)?;
Ok(branch_id)
Ok(branch.id)
})
})
.await

View File

@ -2156,7 +2156,7 @@ fn test_create_vbranch_from_remote_branch() -> Result<()> {
// create a new virtual branch from the remote branch
let branch2_id =
create_virtual_branch_from_branch(&gb_repo, &project_repository, &upstream, None)?;
create_virtual_branch_from_branch(&gb_repo, &project_repository, &upstream, None)?.id;
// shouldn't be anything on either of our branches
let branches = list_virtual_branches(&gb_repo, &project_repository)?;
@ -2292,7 +2292,7 @@ fn test_create_vbranch_from_behind_remote_branch() -> Result<()> {
// create a new virtual branch from the remote branch
let branch1_id =
create_virtual_branch_from_branch(&gb_repo, &project_repository, &remote_branch, None)?;
create_virtual_branch_from_branch(&gb_repo, &project_repository, &remote_branch, None)?.id;
let branches = list_virtual_branches(&gb_repo, &project_repository)?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();