git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: MALET Jean-Luc <jeanluc.malet@gmail.com>
To: git@vger.kernel.org
Subject: [BUG] DOS filetype and pre_commit hook
Date: Wed, 06 Feb 2008 23:22:50 +0100	[thread overview]
Message-ID: <47AA333A.8040403@gmail.com> (raw)

[-- 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


                 reply	other threads:[~2008-02-06 22:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47AA333A.8040403@gmail.com \
    --to=jeanluc.malet@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).