From 80346af154fb6ee57d80f37f33910a82d11ac312 Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Tue, 7 May 2024 00:02:22 +0200 Subject: [PATCH] fixes a possible condition where if integration commit is not found a lot of integreated commits are added to a vbranch --- .../src/virtual_branches/integration.rs | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/crates/gitbutler-core/src/virtual_branches/integration.rs b/crates/gitbutler-core/src/virtual_branches/integration.rs index c1665879c..bffb1634e 100644 --- a/crates/gitbutler-core/src/virtual_branches/integration.rs +++ b/crates/gitbutler-core/src/virtual_branches/integration.rs @@ -303,11 +303,13 @@ fn verify_head_is_clean( .peel_to_commit() .context("failed to peel to commit")?; + let vb_handle = VirtualBranchesHandle::new(project_repository.project().gb_dir()); + let default_target = vb_handle + .get_default_target() + .context("failed to get default target")?; + let mut extra_commits = project_repository - .log( - head_commit.id(), - LogUntil::When(Box::new(|commit| Ok(is_integration_commit(commit)))), - ) + .log(head_commit.id(), LogUntil::Commit(default_target.sha)) .context("failed to get log")?; let integration_commit = extra_commits.pop(); @@ -402,29 +404,3 @@ fn verify_head_is_set( Some(head_name) => Err(errors::VerifyError::InvalidHead(head_name.to_string())), } } - -fn is_integration_commit(commit: &git::Commit) -> bool { - is_integration_commit_author(commit) && is_integration_commit_message(commit) -} - -fn is_integration_commit_author(commit: &git::Commit) -> bool { - is_integration_commit_author_email(commit) && is_integration_commit_author_name(commit) -} - -fn is_integration_commit_author_email(commit: &git::Commit) -> bool { - commit.author().email().map_or(false, |email| { - email == GITBUTLER_INTEGRATION_COMMIT_AUTHOR_EMAIL - }) -} - -fn is_integration_commit_author_name(commit: &git::Commit) -> bool { - commit.author().name().map_or(false, |name| { - name == GITBUTLER_INTEGRATION_COMMIT_AUTHOR_NAME - }) -} - -fn is_integration_commit_message(commit: &git::Commit) -> bool { - commit - .message() - .starts_with(b"GitButler Integration Commit") -}