diff options
author | Kipras Melnikovas <kipras@kipras.org> | 2024-02-23 04:47:05 +0200 |
---|---|---|
committer | Kipras Melnikovas <kipras@kipras.org> | 2024-02-23 05:24:50 +0200 |
commit | d6128a307a56955d7013597b5a2c98fd836aff1d (patch) | |
tree | d4da2637a718adda8c14693035f4f59526b80a28 | |
parent | 468d93b293eee9ff889b9b147a37b001d280ee36 (diff) |
introduce git config option `absorb.oneFixupPerCommit`
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | src/config.rs | 13 | ||||
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 2 |
4 files changed, 39 insertions, 2 deletions
@@ -94,6 +94,16 @@ edit your local or global `.gitconfig` and add the following section maxStack=50 # Or any other reasonable value for your project ``` +### One fixup per fixable commit + +By default, git-absorb will generate separate fixup commits for every absorbable hunk. Instead, can use the `-F` flag to create only 1 fixup commit for all hunks that absorb into the same commit. +To always have this behavior, set + +```ini +[absorb] + oneFixupPerCommit = true +``` + ## TODO - implement force flag diff --git a/src/config.rs b/src/config.rs index f88167c..84cd601 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,9 @@ pub const MAX_STACK_CONFIG_NAME: &str = "absorb.maxStack"; pub const MAX_STACK: usize = 10; +pub const ONE_FIXUP_PER_COMMIT_CONFIG_NAME: &str = "absorb.oneFixupPerCommit"; +pub const ONE_FIXUP_PER_COMMIT_DEFAULT: bool = false; + pub fn max_stack(repo: &git2::Repository) -> usize { match repo .config() @@ -10,3 +13,13 @@ pub fn max_stack(repo: &git2::Repository) -> usize { _ => MAX_STACK, } } + +pub fn one_fixup_per_commit(repo: &git2::Repository) -> bool { + match repo + .config() + .and_then(|config| config.get_bool(ONE_FIXUP_PER_COMMIT_CONFIG_NAME)) + { + Ok(one_commit_per_fixup) => one_commit_per_fixup, + _ => ONE_FIXUP_PER_COMMIT_DEFAULT, + } +} @@ -3,6 +3,7 @@ extern crate slog; use anyhow::{anyhow, Result}; mod commute; +mod config; mod owned; mod stack; @@ -18,9 +19,22 @@ pub struct Config<'a> { pub logger: &'a slog::Logger, } -pub fn run(config: &Config) -> Result<()> { +pub fn run(config: &mut Config) -> Result<()> { let repo = git2::Repository::open_from_env()?; debug!(config.logger, "repository found"; "path" => repo.path().to_str()); + + // here, we default to the git config value, + // if the flag was not provided in the CLI. + // + // in the future, we'd likely want to differentiate between + // a "non-provided" option, vs an explicit --no-<option> + // that disables a behavior, much like git does. + // e.g. user may want to overwrite a config value with + // --no-one-fixup-per-commit -- then, defaulting to the config value + // like we do here is no longer sufficient. but until then, this is fine. + // + config.one_fixup_per_commit |= config::one_fixup_per_commit(&repo); + run_with_repo(config, &repo) } diff --git a/src/main.rs b/src/main.rs index 5ee6fef..26d0edc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,7 +113,7 @@ fn main() { )); } - if let Err(e) = git_absorb::run(&git_absorb::Config { + if let Err(e) = git_absorb::run(&mut git_absorb::Config { dry_run: args.is_present("dry-run"), force: args.is_present("force"), base: args.value_of("base"), |