Skip to content

Commit

Permalink
fix(git): skip git hooks via config param (#499)
Browse files Browse the repository at this point in the history
**Problem:**

HUSKY doesn't necessarily account for all of the ways that git hooks can
be configured.

**Solution:**

Use `git -c core.hooksPath=/dev/null` when wanting to skip hooks.
  • Loading branch information
paularmstrong authored Dec 4, 2023
1 parent a18f2b8 commit 5a6faab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .changeset/proud-apes-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@onerepo/core': patch
'@onerepo/git': patch
'onerepo': patch
---

When running git staging workflow (eg, during `tasks -c pre-commit`), forcibly skip all git hooks, not just using HUSKY environment variables.
26 changes: 6 additions & 20 deletions modules/git/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Graph } from '@onerepo/graph';
import type { Logger, LogStep } from '@onerepo/logger';

const stashPrefix = 'oneRepo_';
const skipHooks = ['-c', 'core.hooksPath=/dev/null'];

export class StagingWorkflow {
#graph: Graph;
Expand Down Expand Up @@ -159,11 +160,8 @@ export class StagingWorkflow {
await run({
name: 'Hide unstaged changes',
cmd: 'git',
args: ['checkout', '--force', '.'],
args: [...skipHooks, 'checkout', '--force', '.'],
runDry: true,
opts: {
env: { HUSKY: '0' },
},
step,
});
}
Expand Down Expand Up @@ -198,11 +196,8 @@ export class StagingWorkflow {
await run({
name: 'Apply stash',
cmd: 'git',
args: ['stash', 'apply', '--quiet', '--index', stashIndex],
args: [...skipHooks, 'stash', 'apply', '--quiet', '--index', stashIndex],
runDry: true,
opts: {
env: { HUSKY: '0' },
},
step,
skipFailures: true,
});
Expand All @@ -214,36 +209,27 @@ export class StagingWorkflow {
await run({
name: 'Restore unstaged changes',
cmd: 'git',
args: ['apply', ...args],
args: [...skipHooks, 'apply', ...args],
skipFailures: true,
runDry: true,
opts: {
env: { HUSKY: '0' },
},
step,
});
} catch (e) {
try {
await run({
name: 'Retry restoring unstaged changes with 3way merge',
cmd: 'git',
args: ['apply', '--3way', ...args],
args: [...skipHooks, 'apply', '--3way', ...args],
runDry: true,
opts: {
env: { HUSKY: '0' },
},
step,
});
} catch (e) {
step.error('Unable to restore unstaged changes due to merge conflict.');
await run({
name: 'Reset to HEAD',
cmd: 'git',
args: ['reset', '--hard', 'HEAD'],
args: [...skipHooks, 'reset', '--hard', 'HEAD'],
runDry: true,
opts: {
env: { HUSKY: '0' },
},
step,
});

Expand Down

0 comments on commit 5a6faab

Please sign in to comment.