From f044c2689b338d08d5f751b8ab3c572671485df5 Mon Sep 17 00:00:00 2001 From: Marc BARBIER Date: Tue, 29 Jun 2021 11:27:42 +0200 Subject: [PATCH] switch to python3 + support fichier destination --- pre-commit | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/pre-commit b/pre-commit index fdf6561..6b377ab 100755 --- a/pre-commit +++ b/pre-commit @@ -1,31 +1,18 @@ -#!/bin/bash -BOLD=`tput bold` -RED=`tput setaf 1` -GREEN=`tput setaf 2` -GREENBOLD=$BOLD$GREEN -REDBOLD=$BOLD$RED -RESET=`tput init` +#!/usr/bin/python3 +import subprocess +import sys +banned=["console.log", "<<<< HEAD"] -git diff --staged | grep -v ^- | grep "console.log" 2> /dev/null 1> /dev/null -if [ $? = 0 ] -then - echo "${REDBOLD}/!\\Console.log detected /!\\" - echo "${REDBOLD}aborting..." - exit 1 -else - echo "${GREENBOLD} No console.log" -fi +triggred=0 +result = subprocess.run(['git', 'diff', '--staged'], stdout=subprocess.PIPE) +diff = result.stdout.decode("utf-8") +files = diff.split("diff --git a/") +for file in files: + for check in banned: + if check in file: + print(check + " detected in:") + print(file.split("\n")[0].split(" b/")[0]) + triggred=1 -git diff --staged | grep -v ^- | grep "<<<<<<< HEAD" 2> /dev/null 1> /dev/null -if [ $? = 0 ] -then - echo "${REDBOLD}/!\\ UNRESOLVED MERGE DETECTED /!\\" - echo "${REDBOLD}aborting..." - exit 1 -else - echo "${GREENBOLD} No unresolved merge" -fi - - -echo $RESET +sys.exit(triggred)