Skip to content
Snippets Groups Projects
Commit 808e234d authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

experiments on using push hook arguments directly

parent 96a4fa11
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,7 @@ do ...@@ -38,7 +38,7 @@ do
echo " -h|-help|--help print this message and exit" echo " -h|-help|--help print this message and exit"
echo " -f|--fix fix files" echo " -f|--fix fix files"
echo " -c|--commit check modified files to be committed only" echo " -c|--commit check modified files to be committed only"
echo " -p|--push check modified files to be pushed only" echo " -p|--push range check modified files to be pushed only"
echo " --no-headers do not check headers" echo " --no-headers do not check headers"
echo " --no-lint do not check lint" echo " --no-lint do not check lint"
exit 0 exit 0
...@@ -48,11 +48,12 @@ do ...@@ -48,11 +48,12 @@ do
HDRCK=headers HDRCK=headers
;; ;;
"-p"|"--push") "-p"|"--push")
REMOTE=$(git config --default origin --get clone.defaultRemoteName) shift
REFERENCE="$REMOTE/$(git rev-parse --abbrev-ref HEAD)" DIFF_ARG=$1
MODE="push" MODE="push"
;; ;;
"-c"|"--commit") "-c"|"--commit")
DIFF_ARG=--cached
MODE="commit" MODE="commit"
;; ;;
"--no-headers") "--no-headers")
...@@ -87,9 +88,8 @@ else ...@@ -87,9 +88,8 @@ else
rm -f "$TMP_STAGED" "$TMP_UNSTAGED" "$TMP_INPUT" "$TMP_INTER" rm -f "$TMP_STAGED" "$TMP_UNSTAGED" "$TMP_INPUT" "$TMP_INTER"
} }
trap cleanup exit trap cleanup exit
git diff --diff-filter ACMR --name-only $DIFF_ARG | sort > "$TMP_STAGED"
git diff --diff-filter ACMR --name-only -z --cached $REFERENCE | sort -z > "$TMP_STAGED" git diff --diff-filter DMR --name-only | sort > "$TMP_UNSTAGED"
git diff --diff-filter DMR --name-only -z | sort -z > "$TMP_UNSTAGED"
if [ ! -s "$TMP_STAGED" ]; if [ ! -s "$TMP_STAGED" ];
then then
......
...@@ -21,20 +21,31 @@ ...@@ -21,20 +21,31 @@
# # # #
########################################################################## ##########################################################################
# Example of installation of this pre-push hook (client side): ROOT=$(git rev-parse --show-toplevel)
# - (cd .git/hooks/ && ln -s ../../dev/git-hooks/pre-push.sh pre-push)
# Note: if you decide to copy the file, the `SCRIPT_DIR` variable must be
# fixed accordingly.
echo "Pre-push Hook..." echo "Pre-push Hook..."
STAGED=$(git diff --diff-filter ACMR --name-only --cached origin/$(git rev-parse --abbrev-ref HEAD) | sort) empty=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
if [ "$STAGED" = "" ]; remote=$1
then
echo "No diff since last push, nothing to do"
exit 0
fi
SCRIPT_DIR=$(dirname -- "$( readlink -f -- "$0"; )") while read local_ref local_oid remote_ref remote_oid
"$SCRIPT_DIR/../check-files.sh" -p || exit 1 do
if test "$local_oid" = "$empty"
then
# Handle delete
:
else
if test "$remote_oid" = "$zero"
then
# New branch, examine all commits
range="$local_oid"
else
# Update to existing branch, examine new commits
range="$remote_oid $local_oid"
fi
"$ROOT/dev/check-files.sh" -p "$range" || exit 1;
fi;
done
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment