Skip to content

Commit 3d6ac4e

Browse files
committed
Merge branch 'sam/feat/pre-commit-hook' into feature/bump-2021
* sam/feat/pre-commit-hook: cleanup adding git lfs support something didn't work, reverting file Adding project id detection initial pass at hooks
2 parents ca264e4 + 709ebcc commit 3d6ac4e

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

RepoUtilities/InstallHooks.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "starting"
2+
xcopy pre-commit.toInstall ../.git/hooks/pre-commit
3+
echo "checking if python is installed, if the following errors out, please install python3"
4+
python3 -c "print('done installing')"

RepoUtilities/InstallHooks.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo "starting"
2+
cp pre-commit.toInstall ../.git/hooks/pre-commit
3+
chmod +x ../.git/hooks/pre-commit
4+
echo "checking if python is installed, if the following errors out, please install python3"
5+
6+
python3 -c "print('done installing')"

RepoUtilities/pre-commit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
import sys
3+
import os
4+
import re
5+
6+
def FailCommit(reason):
7+
print("Oh no! Bad commit! "+reason)
8+
sys.exit(1)
9+
10+
def GetStagedFileContent(filePath):
11+
cmd = 'git show :' + filePath
12+
stream = os.popen(cmd)
13+
return stream.read()
14+
15+
def GetLFSStagedFileContent(filePath):
16+
cmd = f"git cat-file blob :{filePath} | git lfs smudge"
17+
stream = os.popen(cmd)
18+
return stream.read()
19+
20+
output = GetStagedFileContent('Packages/manifest.json')
21+
packages = json.loads(output)['dependencies']
22+
if ('com.unity.multiplayer.virtualprojects' in packages):
23+
FailCommit("Virtual projects in packages")
24+
if ('github' in packages['com.unity.multiplayer.tools'].lower()):
25+
FailCommit("Tools using github package")
26+
27+
content = GetLFSStagedFileContent('ProjectSettings/ProjectSettings.asset')
28+
res = re.search(r'.*cloudProjectId:.*\w+\s*\n', content) != None
29+
if res:
30+
FailCommit("Detected cloud project id in project settings")

RepoUtilities/pre-commit.toInstall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python3 RepoUtilities/pre-commit.py

0 commit comments

Comments
 (0)