Posted By

benpjohnson on 09/15/08


Tagged

Bash windows git


Versions (?)

Git whitespace fixes for windows newlines


 / Published in: Bash
 

Pre 1.6 git has some annoying whitespace checking in it's pre-commit hook. Rather than turn it off I decided to have a go at an automated method to fix the issue.

Running the first line lists the files that have problems. The second just adds a sed to fix the issue

  1. .git/hooks/pre-commit 2>&1 | sed '/^\*/d' | sed 's/:.*//' | uniq
  2.  
  3. for FILE in `.git/hooks/pre-commit 2>&1 | sed '/^\*/d' | sed 's/:.*//' | uniq` ; do sed -ie 's/[[:space:]]*$//' $FILE ; done

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: benpjohnson on September 21, 2008

Doesn't really work for most issues had to disable it in the pre-commit hook file for time being

Posted By: Mikelifeguard on February 17, 2010

One of the seds seems to be wrong. Try:

# Find files with trailing whitespace
for FILE in `exec git diff-index --check --cached --ignore-space-at-eol $against -- | sed '/^[+-]/d' | sed -r 's/:[0-9]+:.*//' | uniq`; do
    # Fix them!
    sed -i 's/[[:space:]]+$//' $FILE
done
Posted By: Mikelifeguard on February 17, 2010

HAH, remove that --ignore-space-at-eol obviously. That's exactly what we're trying to find :D

Posted By: Mikelifeguard on February 17, 2010

Sorry, again! One of my seds has a typo too! This time I've actually copy-pasted from my pre-commit hook instead of typing it out. Note that $c is already found further up in the script. This is $against in my broken example above, and is in the .sample script already - I just shortened it.

for f in `exec git diff-index --cached --check $c -- | sed '/^[-+]/d' | sed -r 's:[0-9]+:.*//' | uniq` ; do
    sed -i 's/[[:space:]]*$//' $f
done

You need to login to post a comment.