Skip to content

Conversation

@ejmr
Copy link
Collaborator

@ejmr ejmr commented Jul 28, 2018

Git allows users to have "templates" for commits which, when they
exist, automatically fill the user's editor with the template contents
whenever they make a commit. This does not prevent the user from
further editing the commit message; all it does is pre-populate the
message with pre-written text.

In an effort to help improve the quality of commit messages on PHP
Mode, this patch introduces a commit template along with a Git hook
that, when applied, will automatically fill commit messages with
said template. The template has comments describing some basic
best-practices for writing Git messages, and has commented-out lines
of some metadata we use, i.e. lines like

GitHub-Issue: #9001
Reviewed-by: Vegeta

This patch updates the Makefile with a new rule, dev, that will
install the hook. However, developers have another way to use the
template, which will be necessary for anyone who happens to already
be using the prepare-commit-msg hook for something: users can open
.git/config in the project's top-level directory (tip: git rev-parse --show-toplevel) and add the following:

[commit]
	template = ./etc/git/commit-template.txt

This will apply the commit template for every commit. In contrast,
the hook will only use the template if it can determine the user does
not already have a template in place or that a different tool has
pre-populated the commit message with some text. So in that regard
the two approachs to using the template are different.

Signed-off-by: Eric James Michael Ritz ejmr@no.current.address

Git allows users to have "templates" for commits which, when they
exist, automatically fill the user's editor with the template contents
whenever they make a commit.  This does not prevent the user from
further editing the commit message; all it does is pre-populate the
message with pre-written text.

In an effort to help improve the quality of commit messages on PHP
Mode, this patch introduces a commit template along with a Git hook
that, when applied, will automatically fill commit messages with
said template.  The template has comments describing some basic
best-practices for writing Git messages, and has commented-out lines
of some metadata we use, i.e. lines like

	GitHub-Issue: #9001
	Reviewed-by: Vegeta

This patch updates the Makefile with a new rule, `dev`, that will
install the hook.  However, developers have another way to use the
template, which will be necessary for anyone who happens to already
be using the `prepare-commit-msg` hook for something: users can open
`.git/config` in the project's top-level directory (tip: `git rev-parse
--show-toplevel`) and add the following:

	[commit]
		template = ./etc/git/commit-template.txt

This will apply the commit template for *every* commit.  In contrast,
the hook will only use the template if it can determine the user does
not already have a template in place or that a different tool has
pre-populated the commit message with some text.  So in that regard
the two approachs to using the template are different.

Signed-off-by: Eric James Michael Ritz <ejmr@no.current.address>
@ejmr
Copy link
Collaborator Author

ejmr commented Jul 28, 2018

Instead of changing Makefile it may be best to provide documentation describing how users can locally configure the commit message template, as described above. I could not decide which approach was best.

@zonuexe zonuexe merged commit b8fb9c8 into master Jul 29, 2018
@zonuexe zonuexe deleted the add-commit-message-template branch July 29, 2018 09:53
@zonuexe
Copy link
Member

zonuexe commented Jul 29, 2018

@ejmr Thanks a lot!

@zonuexe
Copy link
Member

zonuexe commented Jul 29, 2018

This template was used from Magit without problems. 👍

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

Successfully merging this pull request may close these issues.

3 participants