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
๐