From 3f2d54c0414aa9f16e7c81c4ab1d21ab199fdf7a Mon Sep 17 00:00:00 2001 From: Philipp Kramer Date: Fri, 24 Feb 2023 16:27:12 +0100 Subject: [PATCH] add hooks --- README.md | 6 ++++++ hooks/post-commit.disabled | 20 ++++++++++++++++++++ hooks/post-merge | 15 +++++++++++++++ hooks/pre-commit | 25 +++++++++++++++++++++++++ setup.sh | 7 +++++++ 5 files changed, 73 insertions(+) create mode 100644 README.md create mode 100644 hooks/post-commit.disabled create mode 100644 hooks/post-merge create mode 100644 hooks/pre-commit create mode 100644 setup.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..f416ac8 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +These hooks for git make it possible to efficiently use Powerpoint in a git repository. + +When creating or cloning the repository locally run setup.sh first to copy the hook scripts into the .git folder. + +Everytime a .pptx file is committed its unzipped contents will be committed instead. +After a pull the file is zipped back into a .pptx. \ No newline at end of file diff --git a/hooks/post-commit.disabled b/hooks/post-commit.disabled new file mode 100644 index 0000000..c25a602 --- /dev/null +++ b/hooks/post-commit.disabled @@ -0,0 +1,20 @@ +#!/bin/sh + +echo "Ich bin der Post Commit und jetzt disabled" + +#chmod -x .git/hooks/post-commit # disable hook +mv .git/hooks/post-commit .git/hooks/post-commit.disabled + +for f in $(cat .changes) +do + echo "File: $f" + git rm --cached $f + new_dir=".$(basename $f)" + new_path="$(dirname $f)/$new_dir" + git add $new_path +done +rm .changes +echo "Jetzt das amend" + +git commit --amend --reuse-message=HEAD --no-verify +echo "End post commit" \ No newline at end of file diff --git a/hooks/post-merge b/hooks/post-merge new file mode 100644 index 0000000..61668a5 --- /dev/null +++ b/hooks/post-merge @@ -0,0 +1,15 @@ +#!/bin/bash +echo "Running Post-Merge" +dirs=$(find -type d -iname "*.pptx") +for d in $dirs +do + echo "creating Powerpoint for $d" + cd $d + foldername="$(basename $d)" + echo "foldername=$foldername" + filename="${foldername:1}" + echo "filename=$filename" + + zip -r ../$filename * + cd .. +done diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100644 index 0000000..bc069e6 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,25 @@ +#!/bin/sh + +files=$(git diff --cached --name-only --diff-filter=ACM) +rm .changes +touch .changes +for f in $files +do + echo "File: $f" + if [[ ( $f == *.ppt ) || ( $f == *.pptx ) ]] + then + echo "Unzipping Powerpoint: $f" + new_dir=".$(basename $f)" + new_path="$(dirname $f)/$new_dir" + echo "new_dir= $new_dir" + echo "new_path= $new_path" + + rm -r $new_path + unzip $f -d $new_path + echo $f >> .changes + mv .git/hooks/post-commit.disabled .git/hooks/post-commit # enable hook + echo "Post-commit enabled" + fi +done + +# diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..0d46a4b --- /dev/null +++ b/setup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cp hooks/post-merge .git/hooks/ +cp hooks/post-commit.disabled .git/hooks/ +cp hooks/pre-commit .git/hooks/ + +.git/hooks/post-merge \ No newline at end of file