Skip to content

Instantly share code, notes, and snippets.

@malb

malb/post-commit.sh

Last active Mar 6, 2016
Embed
What would you like to do?
git post-commit hook for committing compiled PDFs to different branch
#!/bin/bash
out="$(pwd)/out/"
changed_files=$(git diff-tree --no-commit-id --name-only -r HEAD)
do_the_work_tex() {
(
dir="$1"
filename="$2"
extension="$3"
cd "$dir"
latexmk -xelatex -pdf -shell-escape "$filename.$extension"
mkdir -p "$out/$dir"
cp "$filename.pdf" "$out/$dir/$filename.pdf"
)
}
commit_the_work() {
(
unset GIT_INDEX_FILE
unset GIT_WORK_TREE
unset GIT_DIR
commit_msg=$(git log -1 --pretty=oneline)
cd "$out"
git add -A
git commit -a -m "source: $commit_msg"
)
}
for fullfile in $changed_files; do
dir=$(dirname "$fullfile")
filename=$(basename "$fullfile")
extension="${filename##*.}"
filename=$(basename "$fullfile" ".$extension")
if [ "$extension" = "tex" ]; then
do_the_work_tex "$dir" "$filename" "$extension"
fi
done
commit_the_work
#!/bin/bash
unset GIT_INDEX_FILE
unset GIT_WORK_TREE
unset GIT_DIR
out="$(pwd)/out"
cd "$out"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.