forked from cloudaper/sketch-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
post-checkout
executable file
·57 lines (46 loc) · 1.69 KB
/
post-checkout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# post-checkout hook for Sketch files Git tracking
# Derived from https://github.com/cloudaper/sketch-git-hooks
# Set UTF-8 encoding
export LANG=UTF-8
# Needed to work in SourceTree
export PATH=/usr/local/bin:$PATH
# Git repository absolute path
git_root=`git rev-parse --show-toplevel`
# Unzipped Sketch files path
source_directory_name="_source"
source_root="$git_root/$source_directory_name"
# Local backups directory path
backup_root="$git_root/_backup"
backup_date=$(date +%Y%m%d-%H%M%S)
for source_directory in $(find "$source_directory_name" -type d | grep ".sketch$")
do
# Sketch file path
sketch=`echo "$git_root/$source_directory" | sed "s/$source_directory_name\///"`
# Sketch file directory path
sketch_directory=`dirname "$sketch"`
echo "Processing '`basename $sketch`'."
if mkdir -p "$sketch_directory"
then
# Backup existing Sketch file
backup_path=`echo "$backup_root/$backup_date/$source_directory" | sed "s/$source_directory_name\///"`
mkdir -p "`dirname $backup_path`"
cp "$sketch" "$backup_path"
# Zip the directory to update the Sketch file
cd "$source_directory"
if zip -rq "$sketch" *
then
echo " '`basename $sketch`' Sketch file generated."
else
echo " Couldn't generate '`basename $sketch`' Sketch file."
exit 1
fi
cd "$git_root"
else
echo " Couldn't create '$sketch_directory' directory."
exit 1
fi
done
# Run Git LFS hook
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 "$@"