Skip to content

Commit b598738

Browse files
authored
Ignore asset files starting with dot (#8)
Unity does not create meta for files starting with dot. Closes#7
1 parent e24c2b6 commit b598738

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

‎.github/workflows/bats.yml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Bats
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
branches: [ master ]
7+
8+
jobs:
9+
unit-test:
10+
runs-on: ubuntu-latest
11+
name: Bats
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: install bats
16+
run: |
17+
git clone --depth=1 https://github.com/sstephenson/bats.git
18+
19+
- name: run tests
20+
run: bats/bin/bats ./tests.bat

‎scripts/pre-commit‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exec 1>&2
2323
git diff --cached --name-only --diff-filter=A -z $against -- "$ASSETS_DIR"|whileread -d $'\0' f;do
2424
ext="${f##*.}"
2525
base="${f%.*}"
26+
filename="$(basename "$f")"
2627

2728
if [ "$ext"="meta" ];then
2829
if [ $(git ls-files --cached -- "$base"| wc -l)= 0 ];then
@@ -35,7 +36,7 @@ Please add \`$base' to git as well.
3536
EOF
3637
exit 1
3738
fi
38-
else
39+
elif [ "${filename##.*}"!='' ];then
3940
p="$f"
4041
while [ "$p"!="$ASSETS_DIR" ];do
4142
if [ $(git ls-files --cached -- "$p.meta"| wc -l)= 0 ];then

‎tests.bat‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bats
2+
3+
PRE_COMMIT="$BATS_TEST_DIRNAME/scripts/pre-commit"
4+
5+
setup(){
6+
git init repo >&2
7+
cd repo
8+
mkdir Assets
9+
}
10+
11+
teardown(){
12+
cd ..
13+
rm -rf repo
14+
}
15+
16+
@test "ensuring .meta is commit"{
17+
touch Assets/assets
18+
git add Assets/assets
19+
run "$PRE_COMMIT"
20+
[ "$status" -eq 1 ]
21+
[ "${lines[0]}" = "Error: Missing meta file." ]
22+
23+
touch Assets/assets.meta
24+
git add Assets/assets.meta
25+
run "$PRE_COMMIT"
26+
[ "$status" -eq 0 ]
27+
}
28+
29+
@test "ignoring assets file which starts with dot"{
30+
touch Assets/.assets
31+
git add --force Assets/.assets
32+
run "$PRE_COMMIT"
33+
[ "$status" -eq 0 ]
34+
}

0 commit comments

Comments
(0)