Skip to content

Commit b18a0fb

Browse files
authored
Merge pull request #470 from capitalone-contributions/wrslatz-simple-git-fix
fix: remove unneeded git hooks config
2 parents 0adfa42 + eb5405b commit b18a0fb

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/server/git/controller.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ export const syncReposHandler = async ({
5959
config: [
6060
`user.name=pma[bot]`,
6161
`user.email=${input.source.octokit.installationId}+pma[bot]@users.noreply.github.com`,
62-
// Disable any global git hooks to prevent potential interference when running the app locally
63-
'core.hooksPath=/dev/null',
6462
],
6563
}
6664

@@ -129,7 +127,7 @@ export const syncReposHandler = async ({
129127
)
130128

131129
// Push this back to the source branch to retrigger the sync
132-
await git.push(['--force'])
130+
await git.push(['--no-verify', '--force'])
133131

134132
// Return to end function call
135133
return {
@@ -147,12 +145,12 @@ export const syncReposHandler = async ({
147145
gitApiLogger.debug('Checked out branch', input.destination.branch)
148146

149147
// Fast Forward merge the source branch on top of the destination branch
150-
await git.merge(['--ff-only', input.source.branch]) // shouldn't fail because of check above, but nothing done to handle a failure
148+
await git.merge(['--no-verify', '--ff-only', input.source.branch]) // shouldn't fail because of check above, but nothing done to handle a failure
151149
gitApiLogger.debug(
152150
`Merged source branch: ${input.source.branch} into destination branch: ${input.destination.branch} using fast forward`,
153151
)
154152

155-
await git.push(['--force'])
153+
await git.push(['--no-verify', '--force'])
156154

157155
gitApiLogger.debug(
158156
`Pushed to ${input.destination.org}/${input.destination.repo}/${input.destination.branch}`,

src/server/repos/controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ export const createMirrorHandler = async ({
9494
`user.name=pma[bot]`,
9595
// We want to use the private installation ID as the email so that we can push to the private repo
9696
`user.email=${privateInstallationId}+pma[bot]@users.noreply.github.com`,
97-
// Disable any global git hooks to prevent potential interference when running the app locally
98-
'core.hooksPath=/dev/null',
9997
],
10098
}
10199
const git = simpleGit(tempDir, options)
@@ -149,11 +147,11 @@ export const createMirrorHandler = async ({
149147
newRepo.data.name,
150148
)
151149
await git.addRemote('upstream', upstreamRemote)
152-
await git.push('upstream', defaultBranch)
150+
await git.push(['--no-verify', 'upstream', defaultBranch])
153151

154152
// Create a new branch on both
155153
await git.checkoutBranch(input.newBranchName, defaultBranch)
156-
await git.push('origin', input.newBranchName)
154+
await git.push(['--no-verify', 'origin', input.newBranchName])
157155

158156
reposApiLogger.info('Mirror created', {
159157
org: newRepo.data.owner.login,

test/server/git/controller.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,13 @@ describe('Git controller', () => {
187187
'destination/destinationBranch',
188188
)
189189
expect(gitMock.merge).toHaveBeenCalledTimes(1)
190-
expect(gitMock.merge).toHaveBeenCalledWith(['--ff-only', 'sourceBranch'])
190+
expect(gitMock.merge).toHaveBeenCalledWith([
191+
'--no-verify',
192+
'--ff-only',
193+
'sourceBranch',
194+
])
191195
expect(gitMock.push).toHaveBeenCalledTimes(1)
192-
expect(gitMock.push).toHaveBeenCalledWith(['--force'])
196+
expect(gitMock.push).toHaveBeenCalledWith(['--no-verify', '--force'])
193197
})
194198

195199
it('should be syncable, have the environment flag set to true, but not be a merge commit', async () => {
@@ -265,9 +269,13 @@ describe('Git controller', () => {
265269
'destination/destinationBranch',
266270
)
267271
expect(gitMock.merge).toHaveBeenCalledTimes(1)
268-
expect(gitMock.merge).toHaveBeenCalledWith(['--ff-only', 'sourceBranch'])
272+
expect(gitMock.merge).toHaveBeenCalledWith([
273+
'--no-verify',
274+
'--ff-only',
275+
'sourceBranch',
276+
])
269277
expect(gitMock.push).toHaveBeenCalledTimes(1)
270-
expect(gitMock.push).toHaveBeenCalledWith(['--force'])
278+
expect(gitMock.push).toHaveBeenCalledWith(['--no-verify', '--force'])
271279
})
272280

273281
it('should be syncable, have the environment flag set to true, be a merge commit, but not be a merge to main branch', async () => {
@@ -348,9 +356,13 @@ describe('Git controller', () => {
348356
'destination/destinationBranch',
349357
)
350358
expect(gitMock.merge).toHaveBeenCalledTimes(1)
351-
expect(gitMock.merge).toHaveBeenCalledWith(['--ff-only', 'sourceBranch'])
359+
expect(gitMock.merge).toHaveBeenCalledWith([
360+
'--no-verify',
361+
'--ff-only',
362+
'sourceBranch',
363+
])
352364
expect(gitMock.push).toHaveBeenCalledTimes(1)
353-
expect(gitMock.push).toHaveBeenCalledWith(['--force'])
365+
expect(gitMock.push).toHaveBeenCalledWith(['--no-verify', '--force'])
354366
})
355367

356368
it('should be syncable, have the environment flag set to true, be a merge commit, and be a merge to main branch,', async () => {
@@ -429,6 +441,6 @@ describe('Git controller', () => {
429441
expect(gitMock.reset).toHaveBeenCalledTimes(1)
430442
expect(gitMock.reset).toHaveBeenCalledWith(['--hard', 'HEAD^2'])
431443
expect(gitMock.push).toHaveBeenCalledTimes(1)
432-
expect(gitMock.push).toHaveBeenCalledWith(['--force'])
444+
expect(gitMock.push).toHaveBeenCalledWith(['--no-verify', '--force'])
433445
})
434446
})

0 commit comments

Comments
 (0)