git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] DOS filetype and pre_commit hook
@ 2008-02-06 22:22 MALET Jean-Luc
  0 siblings, 0 replies; only message in thread
From: MALET Jean-Luc @ 2008-02-06 22:22 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

I use git for tracking change on the project I'm working on and the 
sourcecode is in dos text encoding (<CR><LF>)
when I commit I have to use the --no-verify option because the perl part 
of the hook (btw isn't it possible to have git not depend on perl?) 
don't use the right regexp to track if there is trailing whitespace
the corresponding regex to be used with grep is :
grep -E '^\+.*[[:blank:]]+[[:space:]]$'

because <CR> is matched by [[:space:]] and then a line like :

no trailing whitespace<CR><LF>

will trigger a trailing whitespace event

See the attached file that correct the issue

Best Regards,
JLM

-- 
KISS! (Keep It Simple, Stupid!)
(garde le simple, imbécile!)
"mais qu'est-ce que tu m'as pondu comme usine à gaz? fait des choses 
simples et qui marchent, espèce d'imbécile!"

[-- Attachment #2: pre-commit --]
[-- Type: application/octet-stream, Size: 1822 bytes --]

#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, make this file executable.

# This is slightly modified from Andrew Morton's Perfect Patch.
# Lines you introduce should not have trailing whitespace.
# Also check for an indentation that has SP before a TAB.

output_failing_line() {
	while [ $# -gt 0 ]; do
		lineno=${1/:*/}
		lineno=$((${lineno}-5))
		line=${1/*+/}
		echo "${lineno} : ${line}"
		shift
	done
}

if git-rev-parse --verify HEAD 2>/dev/null
then
	OLDIFS=${IFS}
	IFS=$'\n'
	error=0
	FILE_LIST=$(git-diff-index --name-only  -M --cached  HEAD --)
	for file in ${FILE_LIST}; do
		line_count=$(wc -l ${file})
		line_count=${line_count/ */}
		trailing=$(git-diff -p --unified=${line_count} --cached HEAD -- ${file} | grep -En '^\+.*[[:blank:]]+[[:space:]]$')
		badindent=$(git-diff -p --unified=${line_count} --cached HEAD -- ${file} | grep -En '^\+[ ]*	')
		badline=$(git-diff -p --unified=${line_count} --cached HEAD -- ${file} | grep -En '^\+(?:[<>=]){7}')
		if [ -n "${trailing}" ] || [ -n "${badindent}" ] || [ -n "${badline}" ]; then
			echo
			echo "------ FAILED PRE COMMIT CHECK -----"
			echo You have some suspicious patch lines:
			echo ${file} : trailing whitespace
			output_failing_line ${trailing}
			echo ${file} : indent SP followed by a TAB
			output_failing_line ${badindent}
			echo ${file} : unresolved merge conflict
			output_failing_line ${badline}
			echo "------ FAILED PRE COMMIT CHECK -----"
			error=1
		fi
	done
   exit ${error}
else
	# NEEDSWORK: we should produce a diff with an empty tree here
	# if we want to do the same verification for the initial import.
	:
fi


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-06 22:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-06 22:22 [BUG] DOS filetype and pre_commit hook MALET Jean-Luc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).