Skip to content

Commit

Permalink
Allow fixing (editing) invalid commit message interactively
Browse files Browse the repository at this point in the history
Before, in interactive mode, an invalid commit message would have
resulted in the user being asked:
  Continue anyway? [yes/no]
Now there's also the option of editing the message:
  Continue anyway? [yes/no/edit]

Also, now if the user gives an invalid reply i.e. types 'ues' the
script won't exit immediately but prints an error message and waits
for another response.

The option of editing the commit message is given only if the input
(i.e. the commit message) is passed in as a regular file. This is
always the case when lint-commit-msg is used in commit-msg hook.
Even if the user runs
  git commit -m "..."
the commit message is written into a temporary file that is passed
to commit-msg hook (and then to lint-commit-msg).

So, in which case the user is prevented from selecting 'edit'? When
the commit message is fed into lint-commit-msg via stdin. However,
this can only happen when lint-commit-msg is run standalone... and
in that case the interactive mode is not used... unless LCM_INTERACTIVE
is set to 'always'. So, that's the corner case when the user should
not be able to edit the commit message.

Other possibility is a file without 'write' permission
  LCM_INTERACTIVE=always lint-commit-msg not-writable-file.txt
in which case trying to edit the file would be pointless.
  • Loading branch information
laurivan committed Apr 19, 2024
1 parent 7f1cdad commit 4e54a80
Show file tree
Hide file tree
Showing 4 changed files with 589 additions and 351 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ERROR: commit message not properly formatted
- line 1: subject not capitalized
add first version of REST client and instructions how to use it with HTTPS
Continue anyway? [yes/no] no
Continue anyway? [yes/no/edit] no
Aborting commit!
Commit message saved in .git/lint-commit-msg.MSG
$
Expand Down Expand Up @@ -160,6 +160,9 @@ The following sections describes each configuration variable and

The variables above will also accept values `true` (alias for `always`) and `false` (alias for `never`).

`lint-commit-msg` also inspects `GIT_EDITOR`, `VISUAL`, and `EDITOR` (in this order) for a text editor
to launch if the user wishes to edit an invalid commit message interactively.

### Modifying rules

| Environment variable | Description | Default value |
Expand Down
Loading

0 comments on commit 4e54a80

Please sign in to comment.