-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprohibit_image_files.sh
executable file
·53 lines (48 loc) · 1.78 KB
/
prohibit_image_files.sh
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
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
function list_bad_files {
oldref="$1"
newref="$2"
filename_pattern="$3"
maxbytes="$4"
git rev-list --objects "${oldref}..${newref}" | \
grep -E "$filename_pattern" | \
git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' | \
(
while read -r objectname objecttype objectsize path; do
if [[ "$objecttype" == "blob" ]] && [[ "$objectsize" -gt "$maxbytes" ]]; then
echo "$path"
fi
done
)
return 0
}
legacy_snapshots=$(list_bad_files "$1" "$2" "src/__image_snapshots__" 0)
if [[ -n "$legacy_snapshots" ]]; then
echo ""
echo "-----------------------------------------------------------------------------"
echo "Please do not commit images to src/__image_snapshots__. We've stopped"
echo "commiting visual regression tests directly to the repository. We now use"
echo "git-lfs to store pointers to externally-managed files in test/image_snapshots."
echo "Please see docs/development.md for more info about git-lfs."
echo "-----------------------------------------------------------------------------"
echo ""
echo "$legacy_snapshots"
exit 1
fi
raw_snapshot_files=$(list_bad_files "$1" "$2" "test/image_snapshots" 140)
if [[ -n "$raw_snapshot_files" ]]; then
echo ""
echo "-----------------------------------------------------------------------------"
echo "Please do not commit raw images to test/image_snapshots. The files in"
echo "this directory should be git-lfs pointers. This allows us to prevent the"
echo "repository from bloating over time. Please see docs/development.md for more"
echo "info about git-lfs."
echo "-----------------------------------------------------------------------------"
echo ""
echo "$raw_snapshot_files"
exit 1
fi
exit 0