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"
@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