Skip to content

Commit

Permalink
feat: use SKIP_SIMPLE_GIT_HOOKS=1 for bypassing
Browse files Browse the repository at this point in the history
  • Loading branch information
bhanufyi committed Sep 24, 2023
1 parent 10f1ded commit 6ad9fe4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ You should use `--no-verify` option

https://bobbyhadz.com/blog/git-commit-skip-hooks#skip-git-commit-hooks

If you need to bypass hooks for multiple Git operations, setting the SIMPLE_GIT_HOOKS environment variable can be more convenient. Once set, all subsequent Git operations in the same terminal session will bypass the associated hooks.
If you need to bypass hooks for multiple Git operations, setting the SKIP_SIMPLE_GIT_HOOKS environment variable can be more convenient. Once set, all subsequent Git operations in the same terminal session will bypass the associated hooks.

```sh
# Set the environment variable
export SIMPLE_GIT_HOOKS=0
export SKIP_SIMPLE_GIT_HOOKS=1

# Subsequent Git commands will skip the hooks
git add .
Expand Down
4 changes: 2 additions & 2 deletions simple-git-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const VALID_OPTIONS = ['preserveUnused']

const PREPEND_SCRIPT =
"#!/bin/sh\n\n" +
'if [ "$SIMPLE_GIT_HOOKS" = "0" ]; then\n' +
' echo "[INFO] SIMPLE_GIT_HOOKS is set to 0, skipping hook."\n' +
'if [ "$SKIP_SIMPLE_GIT_HOOKS" = "1" ]; then\n' +
' echo "[INFO] SKIP_SIMPLE_GIT_HOOKS is set to 1, skipping hook."\n' +
" exit 0\n" +
"fi\n\n";

Expand Down
6 changes: 3 additions & 3 deletions simple-git-hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ afterEach(() => {
projectWithUnusedConfigurationInPackageJsonPath,
projectWithCustomConfigurationFilePath,
].forEach((testCase) => {
delete process.env.SIMPLE_GIT_HOOKS;
delete process.env.SKIP_SIMPLE_GIT_HOOKS;
removeGitHooksFolder(testCase);
});
});
Expand Down Expand Up @@ -295,15 +295,15 @@ test.each([
})


test("bypasses hooks when SIMPLE_GIT_HOOKS is set to 0", () => {
test("bypasses hooks when SKIP_SIMPLE_GIT_HOOKS is set to 1", () => {
execSync("git init \
&& git config user.name github-actions \
&& git config user.email [email protected]", { cwd: projectWithConfigurationInPackageJsonPath });

createGitHooksFolder(projectWithConfigurationInPackageJsonPath);

spc.setHooksFromConfig(projectWithConfigurationInPackageJsonPath);
process.env.SIMPLE_GIT_HOOKS = '0'; // Set environment variable
process.env.SKIP_SIMPLE_GIT_HOOKS = '1'; // Set environment variable
let errorOccured = false;
try {
execSync('git add . && git commit --allow-empty -m "Test commit" && git commit --allow-empty -am "Change commit msg"', {
Expand Down

0 comments on commit 6ad9fe4

Please sign in to comment.