Skip to content

Commit 664fc01

Browse files
author
Sekiphp
committed
Handling correctly text files, rm files
1 parent 93a8f12 commit 664fc01

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

git/commit_helper.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ git status -su | tr \\r \\n | while read -r line ;
3636
do
3737
FILE=$(echo "$line" | awk '{$1 = ""; print substr($0,2)}')
3838
STATUS=$(echo "$line" | awk '{print substr($1,0,2)}')
39+
FILE_MIME=$(file --mime-type "$FILE" | grep -c text)
3940

4041
show_hr
4142

4243
tput smso
4344
echo "Checking file: $FILE (status $STATUS)"
4445
tput rmso
4546

46-
if [ "$STATUS" = "M" ] || [ "$STATUS" = "AM" ] || [ "$STATUS" = "MM" ];
47+
if [[ "$FILE_MIME" = 0 ]];
48+
then
49+
echo "I'm not able to show content of binary file!"
50+
elif [ "$STATUS" = "M" ] || [ "$STATUS" = "AM" ] || [ "$STATUS" = "MM" ];
4751
then
4852
gdiff=$(git diff --color "$FILE")
4953

@@ -90,6 +94,9 @@ do
9094
then
9195
git reset "$FILE"
9296
echo "File was unstaged"
97+
elif [[ "$cmd" = "rm" ]];
98+
then
99+
rm "$FILE"
93100
fi
94101

95102
done

0 commit comments

Comments
 (0)