diff --git a/Cargo.lock b/Cargo.lock index 5fabf49a2c..ff16939cc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3660,6 +3660,7 @@ dependencies = [ "base64 0.22.1", "bstr", "but-core", + "but-gerrit", "but-rebase", "but-settings", "but-status", diff --git a/crates/gitbutler-branch-actions/src/squash.rs b/crates/gitbutler-branch-actions/src/squash.rs index 976ad3f2c6..b1cbf7a870 100644 --- a/crates/gitbutler-branch-actions/src/squash.rs +++ b/crates/gitbutler-branch-actions/src/squash.rs @@ -192,6 +192,9 @@ fn do_squash_commits( let source_commits_without_destination = source_commits .iter() .filter(|&commit| commit.id() != destination_commit.id()); + let gerrit_mode = but_core::RepositoryExt::git_settings(&ctx.gix_repo()?)? + .gitbutler_gerrit_mode + .unwrap_or(false); // Squash commit messages string separating with newlines let new_message = Some(destination_commit) @@ -199,6 +202,15 @@ fn do_squash_commits( .chain(source_commits_without_destination) .filter_map(|c| { let msg = c.message().unwrap_or_default(); + let msg = if gerrit_mode { + // Remove lines containing Change-Id: only if gerrit mode is enabled + msg.lines() + .filter(|line| !line.trim_start().starts_with("Change-Id: I")) + .collect::>() + .join("\n") + } else { + msg.to_string() + }; (!msg.trim().is_empty()).then_some(msg) }) .collect::>() diff --git a/crates/gitbutler-repo/Cargo.toml b/crates/gitbutler-repo/Cargo.toml index bf31e8d36b..8d3ef80249 100644 --- a/crates/gitbutler-repo/Cargo.toml +++ b/crates/gitbutler-repo/Cargo.toml @@ -30,6 +30,7 @@ gitbutler-diff.workspace = true but-rebase.workspace = true but-core.workspace = true but-status.workspace = true +but-gerrit.workspace = true uuid.workspace = true itertools = "0.14" toml.workspace = true diff --git a/crates/gitbutler-repo/src/repository_ext.rs b/crates/gitbutler-repo/src/repository_ext.rs index ac32d19d00..d66c889da2 100644 --- a/crates/gitbutler-repo/src/repository_ext.rs +++ b/crates/gitbutler-repo/src/repository_ext.rs @@ -197,6 +197,10 @@ impl RepositoryExt for git2::Repository { } } + if repo.git_settings()?.gitbutler_gerrit_mode.unwrap_or(false) { + but_gerrit::set_trailers(&mut commit); + } + // TODO: extra-headers should be supported in `gix` directly. let oid = gix_to_git2_oid(repo.write_object(&commit)?);