introduce git config option absorb.oneFixupPerCommit

This commit is contained in:
Kipras Melnikovas 2024-02-23 04:47:05 +02:00
parent 468d93b293
commit d6128a307a
No known key found for this signature in database
GPG key ID: 302DED4F38E4C2C6
4 changed files with 39 additions and 2 deletions

View file

@ -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

View file

@ -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,
}
}

View file

@ -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)
}

View file

@ -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"),