Buckets:

download
raw
2.1 kB
#!/usr/bin/env python3
"""
Smart commit hook that automatically re-stages files modified by pre-commit hooks.
This makes committing with hooks seamless - "the right way is the easy way".
"""
import subprocess
import sys
from typing import List, Tuple
def run_command(cmd: List[str]) -> Tuple[int, str, str]:
"""Run a command and return output."""
result = subprocess.run(cmd, shell=False, capture_output=True, text=True)
return result.returncode, result.stdout, result.stderr
def get_modified_files() -> List[str]:
"""Get list of modified files."""
code, stdout, _ = run_command(["git", "diff", "--name-only"])
if code == 0 and stdout:
return stdout.strip().split("\n")
return []
def get_staged_files() -> List[str]:
"""Get list of staged files."""
code, stdout, _ = run_command(["git", "diff", "--cached", "--name-only"])
if code == 0 and stdout:
return stdout.strip().split("\n")
return []
def main() -> int:
"""Main smart commit logic."""
print("๐Ÿš€ Smart Commit Hook: Checking for hook modifications...")
# Get initial state
initial_modified = set(get_modified_files())
initial_staged = set(get_staged_files())
if not initial_staged:
print("โš ๏ธ No files staged for commit")
return 0
# This hook runs AFTER other pre-commit hooks
# Check if any staged files were modified by hooks
current_modified = set(get_modified_files())
new_modifications = current_modified - initial_modified
if new_modifications:
print(f"๐Ÿ”„ Found {len(new_modifications)} files modified by hooks:")
for file in new_modifications:
print(f" - {file}")
print("๐Ÿ“ Re-staging modified files...")
for file in new_modifications:
run_command(["git", "add", "--", file])
print("โœ… Files re-staged successfully!")
print("๐Ÿ’ก Tip: The commit will proceed with the hook-modified files.")
else:
print("โœ… No additional modifications needed")
return 0
if __name__ == "__main__":
sys.exit(main())

Xet Storage Details

Size:
2.1 kB
ยท
Xet hash:
a7a01b14dc658d6438491867b56db7ffce5bd80a60129924175a2c65ea584819

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.