Replace bash scripts with python scripts
This commit is contained in:
parent
e382a52cf1
commit
b31fe98ad7
12 changed files with 233 additions and 101 deletions
30
pre-commit
30
pre-commit
|
|
@ -1,18 +1,20 @@
|
|||
#!/bin/bash
|
||||
STASH_NAME="pre-commit-$(date %d-%m-%Y-%H-%M-%S)"
|
||||
#!/usr/bin/env python
|
||||
# Use this script in combination with the pre-commit.d directory inside .git/hooks/
|
||||
# to run multiple scripts before commiting
|
||||
|
||||
# Check if the directory is the root directory
|
||||
if [ ! -d ".git/" ]; then
|
||||
echo "Please commit from within the root directory"
|
||||
exit 1
|
||||
fi
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
git stash push --quiet --keep-index --message $STASH_NAME
|
||||
if not os.path.isdir(".git"):
|
||||
sys.exit("Please commit from the project root directory")
|
||||
|
||||
# Run every file inside the pre-commit.d directory
|
||||
for file in .git/hooks/pre-commit.d/*
|
||||
do
|
||||
. $file
|
||||
done
|
||||
files = os.scandir(".git/hooks/pre-commit.d/")
|
||||
|
||||
git stash pop --quiet
|
||||
for executable in files:
|
||||
try:
|
||||
subprocess.check_output(
|
||||
[executable.path], universal_newlines=True, stderr=subprocess.STDOUT
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
sys.exit(e.stdout)
|
||||
|
|
|
|||
Reference in a new issue