[Bug] macOS - Commit after merge - Incorrect parameter passed to Git Hook "prepare-commit-msg"
Asked by TJ Markham:

Minimum Steps to Reproduce {#toc-hId--441103088}
------------------------------------------------

1) Add a "***prepare-commit-msg*** " Git hook ([see Git docs here](https://git-scm.com/docs/githooks#_prepare_commit_msg)) that contains a shell script that outputs the second parameter passed to the hook:  

```
#!/bin/sh

echo $2
```

2) In Sourcetree, perform a merge that has no conflicts ++WITHOUT++ the "***Commit merge immediately (if no conflicts)***" option checked.

3) In Sourcetree, commit the result and click "***Show Full Output***" in the resulting modal window.

4) Observe the output; specifically around the last line before "***Completed successfully***."

Expected Result {#toc-hId-2046409745}
-------------------------------------

The "***prepare-commit-msg*** " script should output the second parameter as: "***merge***".

This can be verified by performing a merge WITH the "***Commit merge immediately (if no conflicts)***" option checked (which will result in the correct value of "***merge***" being printed).

See attached screenshot "***with_option_checked-CORRECT.png***"

![with_option_checked-CORRECT.png](https://community.atlassian.com/t5/image/serverpage/image-id/269979i0AE0EC4B7878851A/image-size/large?v=v2&px=999 "with_option_checked-CORRECT.png")

Actual Result {#toc-hId-238955282}
----------------------------------

The "***prepare-commit-msg*** " script outputs the second parameter as "***message*** " (which is incorrect; it should be "***merge***").

See attached screenshot "***without_option_checked-WRONG.png***"

![without_option_checked-WRONG.png](https://community.atlassian.com/t5/image/serverpage/image-id/269980i66F6A89D9B315ADF/image-size/large?v=v2&px=999 "without_option_checked-WRONG.png")

Real use case \& Why this is an issue {#toc-hId--1568499181}
------------------------------------------------------------

The steps above are simply to demonstrate the issue.

The actual issue occurs when we perform a merge that has conflicts and then try to commit from Sourcetree. This results in the same scenario as seen in the steps above, where Sourcetree does not commit the merge immediately but does provide a commit message. After we resolve the conflicts we commit from Sourcetree and that is when we see the issue.

My team's "***prepare-commnit-msg***" hook relies on the second parameter to customize the commit message when a merge conflict exists. We rely on this commit message to know what files had conflicts so we know what files to review and re-test after a merge with conflicts.

Without the correct parameter, our hook cannot detect that a merge is occurring and therefore cannot customize the commit message.

Workaround {#toc-hId-919013652}
-------------------------------

Do not use Sourcetree; commit from the command line.


Answers:
author: TJ Markham
body: I Filed a bug here: <https://jira.atlassian.com/browse/SRCTREE-8064>

(Originally, I wasn't logged in so I didn't see the "Create" button).

comments: author: Arati Mohanty
body: Thank you [@TJ Markham](/t5/user/viewprofilepage/user-id/5272466) for raising the bug in Jira. We will update our findings there. Kindly do watch the tickets for more updates.


author: TJ Markham
body: thanks [@Arati Mohanty](/t5/user/viewprofilepage/user-id/4851685)!