cocogitto icon indicating copy to clipboard operation
cocogitto copied to clipboard

Add options allowing to select how the log is extracted (cut branches)

Open eburghar opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe.

If you have feature branches and don't want to squash them before merging, considering that cog for now is following the whole commit tree, you end up with some details in your history you don't want necessarily in you CHANGELOG.md.

git log has specific options for this use case (--merges, --first-parent, ...)

Describe the solution you'd like

Add a --first-parent option like git log --first-parent that only consider the active branch when looking for changes.

Describe alternatives you've considered

If you only follow conventional commit on your main branch and not in your feature branch you can achieve the same effect at the expense of phony error messages, but you loose the ability of generating a myfeature.md which is useful if you want a detailed log about a user story that is tracked by the same feature branch.

Additional context

Requirement in SAFE methodology

eburghar avatar Sep 28 '23 04:09 eburghar

Hey @eburghar, That would be an interesting option indeed. Not sure if we want both --merges and --first-parent tho. Maybe --first-parent would be enough since I am also planing to add a feature to ignore non conventional commit and add them in a misc section in the generated changelog.
Thought ?

oknozor avatar Oct 05 '23 06:10 oknozor

Thanks @oknozor for your interest. Yes, --first-parent would be enough. I just stated --merges as another git log flag, but it was not relevant for the aforementioned use case. If you can point a rough direction to start an implementation I can even try to send you a PR.

eburghard avatar Oct 06 '23 07:10 eburghard

General guidelines

First you can get some general info about how to write test and setup the project here: https://github.com/cocogitto/cocogitto/blob/main/CONTRIBUTING.md

Implementing the feature

The current implementation uses git2::Repository::revwalk to explore the commit tree:

https://github.com/cocogitto/cocogitto/blob/17f98dc3ea2ebf233fb19f8e25700fab3664058f/src/git/revspec.rs#L330

You need to create an alternate method to get only the commit first parent using recursion on git2::Commit::parent. Note that it still support the RevSpecPattern used by the current implementation. Trying to reach a commit that's not in the flat (first-parent) tree should produce an error .

Once this is done a --first-parent flag needs to be added to the relevant cli subcommands (check, log, edit, changelog, bump).

I am not sure if this is needed but it might be interesting to add a cog.toml attribute to make --first-parent the default behavior

oknozor avatar Oct 06 '23 09:10 oknozor

note that revwalk has a simplify_first_parent, so the implementation should be pretty straightforward.

eburghar avatar Oct 07 '23 07:10 eburghar