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

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

Closed
pedro-psb opened this issue Oct 28, 2023 · 4 comments
Closed

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

pedro-psb opened this issue Oct 28, 2023 · 4 comments
Assignees

Comments

@pedro-psb
Copy link
Contributor

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
Copy link
Owner

pawamoy commented Oct 29, 2023

Sure, this is something I wanted since the beginning but never got to implement 🙂 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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@pawamoy
Copy link
Owner

pawamoy commented Oct 30, 2023

Yes using a range is a good idea too, I like it. Not sure about the option name: --filter, --filter-commits, --range-filter 🤔 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.

pedro-psb added a commit to pedro-psb/git-changelog that referenced this issue Oct 30, 2023
This feature adds support for filtering the commits that will be used by git-changelog

Issue pawamoy#63: pawamoy#63
Issue pawamoy#16: pawamoy#16
pedro-psb added a commit to pedro-psb/git-changelog that referenced this issue Nov 4, 2023
This feature adds support for filtering the commits that will be used by git-changelog

Issue pawamoy#63: pawamoy#63
Issue pawamoy#16: pawamoy#16
pawamoy pushed a commit that referenced this issue Nov 4, 2023
This feature adds support for filtering the commits that will be used by git-changelog.

Issue #63: #63
Issue #16: #16
PR #64: #64
Co-authored-by: Timothée Mazzucotelli <[email protected]>
@pawamoy pawamoy closed this as completed Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants