PurpleBooth / git-mit

A git hook suite to supercharge your commits! Seamlessly pair program, tag issues, and craft stellar commit messages effortlessly.
Creative Commons Zero v1.0 Universal
68 stars 3 forks source link

Don't modify commits on rebase #1452

Open mattwynne opened 2 months ago

mattwynne commented 2 months ago

Is your feature request related to a problem? Please describe. I've noticed that if I'm working in a branch and I rebase from main, all the commits in the branch end up with the current set of configured co-authors on them. So the original co-author info in the branch is lost.

Describe the solution you'd like When doing a rebase, don't modify the co-author trailer on the rebased commits.

Describe alternatives you've considered Live with it? :)

PurpleBooth commented 2 months ago

ooh that's a tricky one, seems annoying though. I will have a look (also open to PRs if you feel comfortable with that)

PurpleBooth commented 2 months ago

What would you expect, the rebaser to be represented in the trailers, but added to the existing ones, to appear as "the committer" or just make no change?

mattwynne commented 2 months ago

My instinct would be just to leave the commits as-is in the scenario I’m talking about.

I guess there are cases where you’re doing an interactive rebase and you might want something else, but I’d say those are more niche and people can manually add commit trailers if they want to in those situations.

PurpleBooth commented 2 months ago

This is the behaviour I am going to add, seem sensible? I'll do it as opt in then push a change to make it the default with a major bump

Rebases

It might be preferable not to do this on rebase, you can disable this happening on rebase by running

git mit-config mit rebase-behaviour no-change

lets say we have two diverging branches

echo "Lorem Ipsum" >> new-so-no-conflicts.md
git switch -c rebase-demo-branch
git switch -
git commit --all --message="Diverging commit" --quiet
git switch -

Now you can rebase changes without adding any additional trailers

git mit bt se
echo "Lorem Ipsum" >> README.md

git commit --all --message="Rebase behaviour
" --quiet
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson billie@example.com] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <se@example.com>

Then if you rebase the commit stays the same

git mit bt ae
git rebase --reset-author-date "-"
ls .git
echo ----
cat .git/AUTO_MERGE
echo ----
cat .git/HEAD
echo ----
cat .git/ORIG_HEAD
echo ----
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson billie@example.com] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <se@example.com>

The default setting is to modify the co-authored by.

git mit-config mit rebase-behaviour add-to

Now you can rebase changes without adding any additional trailers

git mit bt se
git rebase --reset-author-date "-"
git show --pretty='format:author: [%an %ae] signed-by: [%GS] 
---
%B' -q
author: [Billie Thompson billie@example.com] signed-by: [] 
---
Rebase behaviour

Co-authored-by: Someone Else <se@example.com>
Co-authored-by: Anyone Else <anyone@example.com>
mattwynne commented 2 months ago

Perfect! 🙌🏻

PurpleBooth commented 2 months ago

This should be out now, not defaulted yet.

git mit-config mit set-non-clean-behaviour no-change

to turn it on