Skip to content

Instantly share code, notes, and snippets.

@BinaryGleam
Last active May 5, 2022 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinaryGleam/4e6729de0ee5526e10a730169e539aa3 to your computer and use it in GitHub Desktop.
Save BinaryGleam/4e6729de0ee5526e10a730169e539aa3 to your computer and use it in GitHub Desktop.
Useful unreal engine git hooks
import os, shutil
from subprocess import check_output
bin_path = "Binaries"
print(bin_path + " folder is going to be deleted if it exists")
shutil.rmtree(bin_path, ignore_errors=True)
int_path = "Intermediate"
print(int_path + " folder is going to be deleted if it exists")
shutil.rmtree(int_path, ignore_errors=True)
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-checkout.\n"; exit 2; }
git lfs post-checkout "$@"
git diff HEAD --quiet $1 -- Source
if [[ $? = 1 ]]
then
echo "Differences detected between previous and current branch Source's folder"
py .git/hooks/delete_bin_folders.py "$@"
else
echo "No difference in source folder between previous and current branch"
fi
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-merge.\n"; exit 2; }
git lfs post-merge "$@"
git diff HEAD@{1} --quiet HEAD -- Source
if [[ $? = 1 ]]
then
echo "Pull/Merge detected changes in the source folder"
py .git/hooks/delete_bin_folders.py "$@"
else
echo "No changes detected during Pull/Merge in the source folder"
fi
@BinaryGleam
Copy link
Author

BinaryGleam commented Jul 21, 2021

You can get rid of line 2 and 3 of post-merge and post-checkout if you don't use lfs (working on Unreal, I think you should though!)

In order for this to work, on your repo, just drag and drop those files inside your .git/hooks folder.
If a post-merge and a post-checkout exists already, you'll have to manually add the lines that intereset you for it to work (which should at least be everything after line 4)

You need to have python installed on your system for it to work.

You need to do that on every computer locally.

@joshuataylor
Copy link

This is a great starting point, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment