add hooks

This commit is contained in:
Philipp Kramer 2023-02-24 16:27:12 +01:00
commit 3f2d54c041
5 changed files with 73 additions and 0 deletions

6
README.md Normal file
View file

@ -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.

View file

@ -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"

15
hooks/post-merge Normal file
View file

@ -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

25
hooks/pre-commit Normal file
View file

@ -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
#

7
setup.sh Normal file
View file

@ -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