Skip to content
Permalink
Browse files

Pre-commit hook to check BOM

  • Loading branch information...
dahlia committed Feb 18, 2019
1 parent 409b451 commit 076b160a29f5a8dba67576da8125d2fd3ba4f391
@@ -18,6 +18,9 @@ max_line_length = 80
[*.{cs,md}]
indent_size = 4

[{*.{ps1,sh},hooks/*}]
indent_size = 2

[*.{csproj,xml}]
indent_size = 2
quote_type = double
@@ -143,6 +143,9 @@ script:
[[ "$(git diff --name-only "$commit_range" | grep CHANGES\.md)" != "" ]]
fi
# Check coding styles
- hooks/pre-commit

# Build the whole solution
- msbuild /p:Configuration=Release /r

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
@@ -1,4 +1,4 @@
using Libplanet.Action;
using Libplanet.Action;
using Libplanet.Explorer.Controllers;
using Libplanet.Explorer.Interfaces;
using Microsoft.AspNetCore.Builder;
@@ -1,4 +1,4 @@
using Libplanet.Store;
using Libplanet.Store;

namespace Libplanet.Explorer.Interfaces
{
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary
<wpf:ResourceDictionary
xml:space="preserve"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
@@ -0,0 +1,44 @@
#!/bin/bash
set -e

list_bom_files() {
git grep -lI $'\xEF\xBB\xBF' . | grep -Ev '.sln$'
}

check_bom() {
if list_bom_files > /dev/null; then
{
echo "The following files have BOM:"
list_bom_files | awk '{ print " " $0 }'
echo "You can trim these BOMs by the below command:"
echo " $0 --apply"
} > /dev/stderr
exit 1
fi
}

trim_bom() {
if list_bom_files > /dev/null; then
{
echo "Trimming BOM from the following files:"
list_bom_files | awk '{ print " " $0 }'
} > /dev/stderr

temp_file="$(mktemp)"
list_bom_files | \
while IFS= read -r filename; do
sed '1s/^\xEF\xBB\xBF//' "$filename" > "$temp_file"
cat "$temp_file" > "$filename"
done
else
exit 1
fi
}

if [[ "$1" = "-a" || "$1" = "--apply" ]]; then
trim_bom
else
check_bom
fi

# vim: set filetype=sh ts=2 sw=2 et:

0 comments on commit 076b160

Please sign in to comment.
You can’t perform that action at this time.