diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc5895e..66fba23 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,5 +7,5 @@ repos: name: Check Git Hygiene and PII Leakage entry: python scripts/check_git_hygiene.py language: system - stages: [commit] - always_run: true + stages: [pre-commit] + pass_filenames: true diff --git a/scripts/check_git_hygiene.py b/scripts/check_git_hygiene.py index d7c94cc..746a65f 100644 --- a/scripts/check_git_hygiene.py +++ b/scripts/check_git_hygiene.py @@ -110,9 +110,9 @@ def get_staged_or_tracked_files() -> list[str]: files = [f.strip() for f in res2.stdout.splitlines() if f.strip()] return files -def check_current_hygiene() -> bool: +def check_current_hygiene(specified_files: list[str] = None) -> bool: run_synthetic_canary_test() - files = get_staged_or_tracked_files() + files = specified_files if specified_files else get_staged_or_tracked_files() violations = [] salt, forbidden_hashes = load_forbidden_hashes() @@ -142,7 +142,7 @@ def check_current_hygiene() -> bool: print(f" - {v}") return False - print("[+] Git hygiene check passed cleanly: No un-anonymized PII, real GSTINs, or private data tracked.") + print(f"[+] Git hygiene check passed cleanly: No un-anonymized PII, real GSTINs, or private data tracked ({len(files)} files checked).") return True def scan_full_history() -> bool: @@ -201,9 +201,10 @@ def scan_full_history() -> bool: if __name__ == "__main__": parser = argparse.ArgumentParser(description="Git Hygiene and PII Leakage Auditor") parser.add_argument("--history", action="store_true", help="Scan entire repository commit history and blob tree") + parser.add_argument("files", nargs="*", default=None, help="Files to scan (passed by pre-commit)") args = parser.parse_args() - success = scan_full_history() if args.history else check_current_hygiene() + success = scan_full_history() if args.history else check_current_hygiene(args.files) if not success: sys.exit(1) sys.exit(0)