Skip to content

Commit c397f92

Browse files
committed
Add createSquashCommits configuration option to always create squash commits
1 parent 7edcccd commit c397f92

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

Documentation/git-absorb.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ edit your local or global `.gitconfig` and add the following section:
220220
forceDetach = true
221221
.............................................................................
222222

223+
GENERATE SQUASH COMMITS INSTEAD OF FIXUPS
224+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
225+
226+
By default, git-absorb will generate fixup commits.
227+
To instead generate squash commits, edit your local or global `.gitconfig`
228+
and add the following section:
229+
230+
.............................................................................
231+
[absorb]
232+
createSquashCommits = true
233+
.............................................................................
234+
235+
When this option is set, "fixup commit" may be read as "squash commit"
236+
throughout the documentation. All configuration relating to fixup
237+
commits will apply to the squash commits instead.
238+
223239
GITHUB PROJECT
224240
--------------
225241

src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub const AUTO_STAGE_IF_NOTHING_STAGED_DEFAULT: bool = false;
1919
pub const FIXUP_TARGET_ALWAYS_SHA_CONFIG_NAME: &str = "absorb.fixupTargetAlwaysSHA";
2020
pub const FIXUP_TARGET_ALWAYS_SHA_DEFAULT: bool = false;
2121

22+
pub const CREATE_SQUASH_COMMITS_CONFIG_NAME: &str = "absorb.createSquashCommits";
23+
pub const CREATE_SQUASH_COMMITS_DEFAULT: bool = false;
24+
2225
pub fn unify<'config>(config: &'config Config, repo: &Repository) -> Config<'config> {
2326
Config {
2427
// here, we default to the git config value,
@@ -36,6 +39,12 @@ pub fn unify<'config>(config: &'config Config, repo: &Repository) -> Config<'con
3639
ONE_FIXUP_PER_COMMIT_CONFIG_NAME,
3740
ONE_FIXUP_PER_COMMIT_DEFAULT,
3841
),
42+
squash: config.squash
43+
|| bool_value(
44+
repo,
45+
CREATE_SQUASH_COMMITS_CONFIG_NAME,
46+
CREATE_SQUASH_COMMITS_DEFAULT,
47+
),
3948
force_author: config.force_author
4049
|| bool_value(repo, FORCE_AUTHOR_CONFIG_NAME, FORCE_AUTHOR_DEFAULT),
4150
force_detach: config.force_detach

src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,39 @@ mod tests {
15411541
);
15421542
}
15431543

1544+
#[test]
1545+
fn run_with_squash_config_option() {
1546+
let ctx = repo_utils::prepare_and_stage();
1547+
1548+
repo_utils::set_config_flag(&ctx.repo, "absorb.createSquashCommits");
1549+
1550+
// run 'git-absorb'
1551+
let mut capturing_logger = log_utils::CapturingLogger::new();
1552+
run_with_repo(&capturing_logger.logger, &DEFAULT_CONFIG, &ctx.repo).unwrap();
1553+
1554+
assert_eq!(
1555+
extract_commit_messages(&ctx.repo),
1556+
vec![
1557+
"squash! Initial commit.\n",
1558+
"squash! Initial commit.\n",
1559+
"Initial commit.",
1560+
]
1561+
);
1562+
1563+
log_utils::assert_log_messages_are(
1564+
capturing_logger.visible_logs(),
1565+
vec![
1566+
&json!({"level": "INFO", "msg": "committed"}),
1567+
&json!({"level": "INFO", "msg": "committed"}),
1568+
&json!({
1569+
"level": "INFO",
1570+
"msg": "To squash the new commits, rebase:",
1571+
"command": "git rebase --interactive --autosquash --autostash --root",
1572+
}),
1573+
],
1574+
);
1575+
}
1576+
15441577
#[test]
15451578
fn dry_run_flag() {
15461579
let ctx = repo_utils::prepare_and_stage();

0 commit comments

Comments
 (0)