Skip to content

Commit 7e828bc

Browse files
committed
Add a linter to check for unresolved merges.
1 parent faab67d commit 7e828bc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pre-commit/1-unresolved-merge.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
function test_file {
4+
file="${1}"
5+
6+
if [ ! -f "${file}" ] ; then
7+
return
8+
fi
9+
10+
echo "Running unresolved merge lint..."
11+
# Set -e before and +e after for _required_ linters (i.e.: that will prevent
12+
# commit, e.g.: syntax linters).
13+
# Set +e before and -e after for _optional_ linters (i.e.: that will only
14+
# output messages upon commit, e.g.: style linters).
15+
set -e
16+
grep -i -E '^(<<<<<<<|=======|>>>>>>>)' $file
17+
set +e
18+
}
19+
20+
case "${1}" in
21+
--about )
22+
echo "Check for fishbones (<<<<<<<, =======, >>>>>>>) left by unresolved merges."
23+
;;
24+
25+
* )
26+
for file in $(git diff-index --cached --name-only HEAD | grep -v -E '\.(gif|gz|ico|jpeg|jpg|png|phar|exe|svgz|tff)') ; do
27+
test_file "${file}"
28+
done
29+
;;
30+
esac

0 commit comments

Comments
 (0)