Skip to content

Commit

Permalink
馃悰 Cancel hook when merging (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
teffy committed Mar 12, 2022
1 parent 78f3783 commit c8ff1cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/commands/commit/withHook/index.js
Expand Up @@ -51,7 +51,11 @@ export const cancelIfAmending = () =>
`gitmoji --hook $1 $2`
*/
const commitMessageSource: ?string = process.argv[COMMIT_MESSAGE_SOURCE]
if (commitMessageSource && commitMessageSource.startsWith('commit')) {
if (
commitMessageSource &&
(commitMessageSource.startsWith('commit') ||
commitMessageSource.startsWith('merge'))
) {
process.exit(0)
}
resolve()
Expand Down
19 changes: 19 additions & 0 deletions test/commands/commit.spec.js
Expand Up @@ -303,6 +303,25 @@ describe('commit command', () => {
expect(process.exit).toHaveBeenCalledWith(0)
})
})

describe('with git auto merge trigger by git pull', () => {
it('should cancel the hook', async () => {
mockProcess.mockProcessExit(new Error('ProcessExit0'))
execa.mockReturnValueOnce(Promise.resolve(stubs.gitAbsoluteDir))
// mock that we are merging
process.argv[3] = '.git/MERGE_MSG'
process.argv[COMMIT_MESSAGE_SOURCE] = 'merge'

try {
await commit({ mode: 'hook' })
} catch (e) {
expect(e.message).toMatch('ProcessExit0')
}

expect(process.exit).toHaveBeenCalledWith(0)
})
})

})

describe('guard', () => {
Expand Down

0 comments on commit c8ff1cd

Please sign in to comment.