Skip to content

Commit d01b75e

Browse files
committed
Feature toggle for gerrit mode
1 parent b09ba4e commit d01b75e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

crates/but-core/src/settings.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod git {
99

1010
const GIT_SIGN_COMMITS: &str = "commit.gpgsign";
1111
const GITBUTLER_SIGN_COMMITS: &str = "gitbutler.signCommits";
12+
const GITBUTLER_GERRIT_MODE: &str = "gitbutler.gerritMode";
1213
const SIGNING_KEY: &str = "user.signingKey";
1314
const SIGNING_FORMAT: &str = "gpg.format";
1415
const GPG_PROGRAM: &str = "gpg.program";
@@ -25,6 +26,7 @@ pub mod git {
2526
pub struct GitConfigSettings {
2627
#[serde(rename = "signCommits")]
2728
pub gitbutler_sign_commits: Option<bool>,
29+
pub gitbutler_gerrit_mode: Option<bool>,
2830
pub signing_key: Option<BStringForFrontend>,
2931
pub signing_format: Option<BStringForFrontend>,
3032
pub gpg_program: Option<BStringForFrontend>,
@@ -35,6 +37,7 @@ pub mod git {
3537
fn from(
3638
crate::GitConfigSettings {
3739
gitbutler_sign_commits,
40+
gitbutler_gerrit_mode,
3841
signing_key,
3942
signing_format,
4043
gpg_program,
@@ -43,6 +46,7 @@ pub mod git {
4346
) -> Self {
4447
GitConfigSettings {
4548
gitbutler_sign_commits,
49+
gitbutler_gerrit_mode,
4650
signing_key: signing_key.map(Into::into),
4751
signing_format: signing_format.map(Into::into),
4852
gpg_program: gpg_program
@@ -57,6 +61,7 @@ pub mod git {
5761
fn from(
5862
GitConfigSettings {
5963
gitbutler_sign_commits,
64+
gitbutler_gerrit_mode,
6065
signing_key,
6166
signing_format,
6267
gpg_program,
@@ -65,6 +70,7 @@ pub mod git {
6570
) -> Self {
6671
crate::GitConfigSettings {
6772
gitbutler_sign_commits,
73+
gitbutler_gerrit_mode,
6874
signing_key: signing_key.map(Into::into),
6975
signing_format: signing_format.map(Into::into),
7076
gpg_program: gpg_program.map(Into::into),
@@ -89,6 +95,8 @@ pub mod git {
8995
/// * `commit.gpgsign` which is otherwise valid.
9096
/// * otherwise it defaults to `false` just like Git would.
9197
pub gitbutler_sign_commits: Option<bool>,
98+
/// If `true`, GitButler will create ChangeId trailers and will push references in the Gerrit way
99+
pub gitbutler_gerrit_mode: Option<bool>,
92100
/// `user.signingKey`.
93101
pub signing_key: Option<BString>,
94102
/// `gpg.format`
@@ -108,12 +116,14 @@ pub mod git {
108116
.boolean(GITBUTLER_SIGN_COMMITS)
109117
.or_else(|| config.boolean(GIT_SIGN_COMMITS))
110118
.or(Some(false));
119+
let gitbutler_gerrit_mode = config.boolean(GITBUTLER_GERRIT_MODE).or(Some(false));
111120
let signing_key = config.string(SIGNING_KEY).map(Cow::into_owned);
112121
let signing_format = config.string(SIGNING_FORMAT).map(Cow::into_owned);
113122
let gpg_program = config.trusted_program(GPG_PROGRAM).map(Cow::into_owned);
114123
let gpg_ssh_program = config.trusted_program(GPG_SSH_PROGRAM).map(Cow::into_owned);
115124
Ok(GitConfigSettings {
116125
gitbutler_sign_commits,
126+
gitbutler_gerrit_mode,
117127
signing_key,
118128
signing_format,
119129
gpg_program,

crates/but-core/tests/core/settings.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ mod git {
1212
actual,
1313
GitConfigSettings {
1414
gitbutler_sign_commits: Some(false),
15-
..GitConfigSettings::default()
15+
..GitConfigSettings {
16+
gitbutler_gerrit_mode: Some(false),
17+
..Default::default()
18+
}
1619
},
1720
"by default, None of these are set in a new repository, except for the explicit gpg-sign logic"
1821
);
1922
let expected = GitConfigSettings {
2023
gitbutler_sign_commits: Some(true),
24+
gitbutler_gerrit_mode: Some(false),
2125
signing_key: Some("signing key".into()),
2226
signing_format: Some("signing format".into()),
2327
gpg_program: Some("gpg program".into()),
@@ -40,7 +44,10 @@ mod git {
4044
let repo = gix::open_opts(tmp.path(), gix::open::Options::isolated())?;
4145
let expected = GitConfigSettings {
4246
gitbutler_sign_commits: Some(true),
43-
..Default::default()
47+
..GitConfigSettings {
48+
gitbutler_gerrit_mode: Some(false),
49+
..Default::default()
50+
}
4451
};
4552

4653
repo.set_git_settings(&expected)?;

crates/but-rebase/src/commit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ pub fn create(
110110
{
111111
commit.extra_headers.remove(pos);
112112
}
113-
but_gerrit::set_trailers(&mut commit);
113+
if repo.git_settings()?.gitbutler_gerrit_mode.unwrap_or(false) {
114+
but_gerrit::set_trailers(&mut commit);
115+
}
114116
if repo.git_settings()?.gitbutler_sign_commits.unwrap_or(false) {
115117
let mut buf = Vec::new();
116118
commit.write_to(&mut buf)?;

0 commit comments

Comments
 (0)