Last active
April 13, 2023 06:40
-
-
Save 20chan/4e91dabcd319df14bff40ca2a42caa19 to your computer and use it in GitHub Desktop.
git hook for unstaging unity empty directory meta files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function is_empty() | |
{ | |
if [[ "$1" == *.meta ]]; then | |
filename="${file%.meta}" | |
if [[ -d "$filename" ]]; then | |
files=$(git ls-files "$filename") | |
if [ -z "$files" ]; then | |
return | |
else | |
is_empty "$filename" | |
return | |
fi | |
else | |
echo "no" | |
return | |
fi | |
else | |
if [ -d "$1" ]; then | |
files=$(git ls-files "$1") | |
if [ -z "$files" ]; then | |
echo "" | |
return | |
fi | |
while IFS= read -r file; do | |
is_empty "$file" | |
done <<< "$files" | |
else | |
echo "no" | |
return | |
fi | |
fi | |
} | |
files_changed=$(git diff --cached --name-only --relative) | |
while IFS= read -r file; do | |
if [[ "$file" == *.meta ]]; then | |
filename="${file%.meta}" | |
if [[ -d "$filename" ]]; then | |
empty=$(is_empty "$filename") | |
if [ -z "$empty" ]; then | |
git reset "$file" | |
echo "$filename" | |
fi | |
fi | |
fi | |
done <<< "$files_changed" | |
👍
와 빈파일 메타 없애주는건가요
메타파일 없애주는건 아니고 빈폴더 메타파일이 git에서 stage됐어도 커밋하면 알아서 reset되는 pre-commit hook입니다
빈폴더랑 메타파일은 그대로 남아있게 하는게 목적이라
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
와 빈파일 메타 없애주는건가요