Skip to content

Instantly share code, notes, and snippets.

@20chan
Last active April 13, 2023 06:40
Show Gist options
  • Save 20chan/4e91dabcd319df14bff40ca2a42caa19 to your computer and use it in GitHub Desktop.
Save 20chan/4e91dabcd319df14bff40ca2a42caa19 to your computer and use it in GitHub Desktop.
git hook for unstaging unity empty directory meta files
#!/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"
@choeehb
Copy link

choeehb commented Aug 24, 2020

와 빈파일 메타 없애주는건가요

@FoxRyang
Copy link

👍

@20chan
Copy link
Author

20chan commented Aug 24, 2020

와 빈파일 메타 없애주는건가요

메타파일 없애주는건 아니고 빈폴더 메타파일이 git에서 stage됐어도 커밋하면 알아서 reset되는 pre-commit hook입니다
빈폴더랑 메타파일은 그대로 남아있게 하는게 목적이라

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment