mirror of
https://github.com/tummychow/git-absorb
synced 2024-11-12 23:27:16 +00:00
introduce git config option absorb.oneFixupPerCommit
This commit is contained in:
parent
468d93b293
commit
d6128a307a
4 changed files with 39 additions and 2 deletions
10
README.md
10
README.md
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue