Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag and configuration to generate fixup commits for commits written by another author #143

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Documentation/git-absorb.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: git-absorb
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 04/06/2023
.\" Date: 02/02/2025
.\" Manual: git absorb
.\" Source: git-absorb 0.5.0
.\" Language: English
.\"
.TH "GIT\-ABSORB" "1" "04/06/2023" "git\-absorb 0\&.5\&.0" "git absorb"
.TH "GIT\-ABSORB" "1" "02/02/2025" "git\-absorb 0\&.5\&.0" "git absorb"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -66,9 +66,14 @@ Run rebase if successful
Don\(cqt make any actual changes
.RE
.PP
\-\-force\-author
.RS 4
Generate fixups to commits not made by you
.RE
.PP
\-f, \-\-force
.RS 4
Skip safety checks
Skip all safety checks\&. Generate fixups to commits not made by you (as if by \-\-force\-author) and to non\-branch HEADs
.RE
.PP
\-w, \-\-whole\-file
Expand Down Expand Up @@ -194,6 +199,20 @@ edit your local or global \&.gitconfig and add the following section:
.if n \{\
.RE
.\}
.SS "GENERATE FIXUPS FOR COMMITS NOT AUTHORED BY YOU"
.sp
By default, git\-absorb will only generate fixup commits for commits that were authored by you\&. To always generate fixups for any author\(cqs commits, edit your local or global \&.gitconfig and add the following section:
.sp
.if n \{\
.RS 4
.\}
.nf
[absorb]
forceAuthor = true
.fi
.if n \{\
.RE
.\}
.SH "GITHUB PROJECT"
.sp
https://github\&.com/tummychow/git\-absorb
Expand Down
18 changes: 17 additions & 1 deletion Documentation/git-absorb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ FLAGS
--dry-run::
Don't make any actual changes

--force-author::
Generate fixups to commits not made by you

-f::
--force::
Skip safety checks
Skip all safety checks.
Generate fixups to commits not made by you (as if by --force-author) and to non-branch HEADs

-w::
--whole-file::
Expand Down Expand Up @@ -124,6 +128,18 @@ edit your local or global `.gitconfig` and add the following section:
maxStack=50 # Or any other reasonable value for your project
.............................................................................

GENERATE FIXUPS FOR COMMITS NOT AUTHORED BY YOU
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default, git-absorb will only generate fixup commits for commits that were
authored by you. To always generate fixups for any author's commits,
edit your local or global `.gitconfig` and add the following section:

.............................................................................
[absorb]
forceAuthor = true
.............................................................................

GITHUB PROJECT
--------------

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ edit your local or global `.gitconfig` and add the following section
maxStack=50 # Or any other reasonable value for your project
```

### Generate fixups for commits not authored by you

By default, git-absorb will only generate fixup commits for commits that were authored by you.
Instead, use the `--force-author` flag to generate fixup commits for commits written by any author.
To always have this behavior, set

```ini
[absorb]
forceAuthor = true
```

### 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.
Expand Down Expand Up @@ -134,7 +145,6 @@ By default, git-absorb will create fixup commits with their messages pointing to

## TODO

- implement force flag
- implement remote default branch check
- add smaller force flags to disable individual safety checks
- stop using `failure::err_msg` and ensure all error output is actionable by the user
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub const MAX_STACK_CONFIG_NAME: &str = "absorb.maxStack";
pub const MAX_STACK: usize = 10;

pub const FORCE_AUTHOR_CONFIG_NAME: &str = "absorb.forceAuthor";
pub const FORCE_AUTHOR_DEFAULT: bool = false;

pub const ONE_FIXUP_PER_COMMIT_CONFIG_NAME: &str = "absorb.oneFixupPerCommit";
pub const ONE_FIXUP_PER_COMMIT_DEFAULT: bool = false;

Expand All @@ -20,6 +23,16 @@ pub fn max_stack(repo: &git2::Repository) -> usize {
}
}

pub fn force_author(repo: &git2::Repository) -> bool {
match repo
.config()
.and_then(|config| config.get_bool(FORCE_AUTHOR_CONFIG_NAME))
{
Ok(force_author) => force_author,
_ => FORCE_AUTHOR_DEFAULT,
}
}

pub fn one_fixup_per_commit(repo: &git2::Repository) -> bool {
match repo
.config()
Expand Down
Loading