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 option to remove commit hash from unreleased commits #13

Open
JeanMertz opened this issue May 4, 2020 · 1 comment
Open

add option to remove commit hash from unreleased commits #13

JeanMertz opened this issue May 4, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@JeanMertz
Copy link
Member

JeanMertz commented May 4, 2020

By (optionally) changing the template to skip commit hashes for unreleased commits, it becomes possible to integrate Jilu in a post-commit workflow that automatically amends your commits with the updated changelog.

Without this feature, the amended changes will cause the commit hash to change, and thus you'll have to update the change log again, going into an endless loop.

This is already possible, but requires you to add a custom template to your CHANGELOG.md with these parts updated/removed:

{%- for change in unreleased.changes -%}
- {{ change.type }}: {{ change.description }} ([`{{ change.commit.short_id }}`])
{% endfor %}

{% for change in unreleased.changes %}
[`{{ change.commit.short_id }}`]: {{ url }}/commit/{{ change.commit.id }}
{%- endfor -%}

You can then use a .git/hooks/post-commit hook such as this one:

#!/bin/sh

# Update CHANGELOG.md with latest commit message.
jilu | sponge CHANGELOG.md

# No changes detected.
git diff --quiet --exit-code CHANGELOG.md && exit 0

git add CHANGELOG.md

# We have to manually disable this hook or else we'll get into a loop. There is
# no way to disable "post-commit" hooks using the Git CLI.

gitdir="$(git rev-parse --git-dir)"
hook="$gitdir/hooks/post-commit"
[ -x "$hook" ] && chmod -x "$hook"

git commit --no-verify --amend --no-edit --quiet

chmod +x "$hook"

echo "$(git rev-parse --short HEAD): CHANGELOG.md update amended"
@JeanMertz
Copy link
Member Author

An alternative (better?) approach is to change the template to keep the links to all commits except for the latest (unreleased) change. The last one will get a link pointing to "HEAD", so that it doesn't need a rewrite when the hook runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant