pawamoy / git-changelog

Automatic Changelog generator using Jinja2 templates.
https://pawamoy.github.io/git-changelog
ISC License
136 stars 34 forks source link

feature: Add "initial_commit" option to filter git log range #63

Closed pedro-psb closed 11 months ago

pedro-psb commented 11 months ago

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

In a project I work on, we have changed to semver recently and decided to update the CI release scripts. I want to keep my old changelog untouched and make git-changelog use only commits after we've introduced semver.

Describe the solution you'd like

Add a --initial-commit or option to define a hash or tagname to be used as the initial commit used by git-changelog. If this is approved, I'd like some suggestions for short/long names.

Describe alternatives you've considered

Change history, but no.

Additional context

I've done a quick experiment locally and got it working. I believe I could do a PR next week. Basically:

    def get_log(self) -> str:
        """Get the `git log` output.

        Returns:
            The output of the `git log` command, with a particular format.
        """
        if self.initial_commit:
            range = self.initial_commit + ".."
            try:
                return self.run_git("log", "--date=unix", "--format=" + self.FORMAT, range)
            except CalledProcessError:
                raise ValueError(
                    f"An error ocurred. Maybe the provided commit is not valid: '{self.initial_commit}'")
        return self.run_git("log", "--date=unix", "--format=" + self.FORMAT)
pawamoy commented 11 months ago

Sure, this is something I wanted since the beginning but never got to implement :slightly_smiling_face: See #16. What do you think of --initial-ref or --start-ref (because it can be any Git ref, not just a commit hash)? Most letters are already taken for short options, so maybe -f, --first-ref instead (which leaves room for an eventual -l, --last-ref)?

pedro-psb commented 11 months ago

I've missed that issue. I believe modifying get_log covers "we should also be able to limit the commits being parsed"? In the sense that it filters before parsing.

-f, --first-ref + -l, --last-ref sounds good.

pedro-psb commented 11 months ago

Or maybe --range and clarify it'll be passed directly to git log? This may provide more flexibility for users.

pawamoy commented 11 months ago

Yes using a range is a good idea too, I like it. Not sure about the option name: --filter, --filter-commits, --range-filter :thinking: Ideally the short option is the first letter of the long option, but if that makes an ugly long option we can definitely use whatever short letter is available, like -F, --range. For what it's worth, it's called "revision range" in git-log's manual page.