# commit-msg hook possible bad behavior with -F <file>

3 messages from 2017-12-18 to 2017-12-18. Participants: Seth Raymond, Eric Sunshine.
Thread: https://gitlist.dev/t/47459

## Seth Raymond, 2017-12-18 16:43

Subject: commit-msg hook possible bad behavior with -F <file>
Message-ID: <CAJ4+5mHMD+yW1ZDD6KJSnMtyygLUGiHzNPgPDZUi7+KUvOczkg@mail.gmail.com>
URL: https://gitlist.dev/e/CAJ4%2B5mHMD%2ByW1ZDD6KJSnMtyygLUGiHzNPgPDZUi7%2BKUvOczkg%40mail.gmail.com

```
If a commit is invoked with -F <file>, indicating that the commit
message should be read from an existing file, the the
prepare-commit-msg and commit-msg hooks do not operate on <file>. The
first argument to the hook is always <git_repo>/COMMIT_EDITMSG, rather
than <file>.

Am I wrong in this line of thinking?

-Seth

```

## Eric Sunshine, 2017-12-18 18:31

Subject: Re: commit-msg hook possible bad behavior with -F <file>
Message-ID: <CAPig+cTmRiSfY9+DsvEB7X_cL4AiAmq0FUb-CoDyc3HNDJLtow@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcTmRiSfY9%2BDsvEB7X_cL4AiAmq0FUb-CoDyc3HNDJLtow%40mail.gmail.com
In-Reply-To: <CAJ4+5mHMD+yW1ZDD6KJSnMtyygLUGiHzNPgPDZUi7+KUvOczkg@mail.gmail.com>

```
On Mon, Dec 18, 2017 at 11:43 AM, Seth Raymond <seth.c.raymond@gmail.com> wrote:
> If a commit is invoked with -F <file>, indicating that the commit
> message should be read from an existing file, the the
> prepare-commit-msg and commit-msg hooks do not operate on <file>. The
> first argument to the hook is always <git_repo>/COMMIT_EDITMSG, rather
> than <file>.
>
> Am I wrong in this line of thinking?

The content of <file> gets copied into COMMIT_EDITMSG, so the hook
does see the supplied message, as expected. Given that the hook is
allowed to edit the message, it makes sense that it works on
COMMIT_EDITMSG rather than on <file> directly.

```

## Seth Raymond, 2017-12-18 21:34

Subject: Re: commit-msg hook possible bad behavior with -F <file>
Message-ID: <CAJ4+5mHt-oJTYEeRUeTynbZ5MRNT_CXWQSHoTUP_i-gWeqvmuA@mail.gmail.com>
URL: https://gitlist.dev/e/CAJ4%2B5mHt-oJTYEeRUeTynbZ5MRNT_CXWQSHoTUP_i-gWeqvmuA%40mail.gmail.com
In-Reply-To: <CAPig+cTmRiSfY9+DsvEB7X_cL4AiAmq0FUb-CoDyc3HNDJLtow@mail.gmail.com>

```
I see that line of thinking, and agree that it makes sense. I'm having
problems with an IDE (Qt Creator) and I think I know where the problem
lies now. I believe Qt Creator doesn't actually call git commit until
after the user generates a message in the message box, meaning my
prepare-commit-msg hook is run after I've already written a message
out to <file>.

I don't think there's a fix to it due to the IDE's seemingly-poor
implementation of the git plugin. Thanks for the clarification!

On Mon, Dec 18, 2017 at 1:31 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Mon, Dec 18, 2017 at 11:43 AM, Seth Raymond <seth.c.raymond@gmail.com> wrote:
>> If a commit is invoked with -F <file>, indicating that the commit
>> message should be read from an existing file, the the
>> prepare-commit-msg and commit-msg hooks do not operate on <file>. The
>> first argument to the hook is always <git_repo>/COMMIT_EDITMSG, rather
>> than <file>.
>>
>> Am I wrong in this line of thinking?
>
> The content of <file> gets copied into COMMIT_EDITMSG, so the hook
> does see the supplied message, as expected. Given that the hook is
> allowed to edit the message, it makes sense that it works on
> COMMIT_EDITMSG rather than on <file> directly.

```
