Skip to content

Commit

Permalink
feat(pre-receive): return 0 if breakglassed
Browse files Browse the repository at this point in the history
  • Loading branch information
jguerreiro authored and Jguer committed Sep 30, 2021
1 parent 87a82c9 commit f6e39c3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ggshield/pre_receive_cmd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import traceback
from typing import List
Expand All @@ -10,6 +11,18 @@
from .git_shell import check_git_dir, get_list_commit_SHA


def get_breakglass_option() -> bool:
"""Test all options passed to git for `breakglass`"""
raw_option_count = os.getenv("GIT_PUSH_OPTION_COUNT", None)
if raw_option_count is not None:
option_count = int(raw_option_count)
for option in range(option_count):
if os.getenv(f"GIT_PUSH_OPTION_{option}", "") == "breakglass":
return True

return False


@click.command()
@click.argument("prereceive_args", nargs=-1, type=click.UNPROCESSED)
@click.pass_context
Expand All @@ -21,6 +34,11 @@ def prereceive_cmd(
"""
config = ctx.obj["config"]

breakglass = get_breakglass_option()
if breakglass:
click.echo("breakglass detected. Skipping GitGuardian pre-receive hook.")
return 0

oldref, newref, *_ = sys.stdin.read().strip().split()

if newref == EMPTY_SHA:
Expand Down

0 comments on commit f6e39c3

Please sign in to comment.