Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› cancel hook when automerge by git pull #783

Merged
merged 1 commit into from Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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