# HG changeset patch # User Stepan Koltsov # Date 1309547572 -14400 # Node ID f335794353785e8407aea782a24b1719e76eb6cc # Parent 23c2d7d25329805016315ac93ed15e7612fd9abb eol: fix missing trailing newlines in comitted files Some text editors (Eclipse, for example) do not add trailing newlines, so diffs often contain annoying "\ No newline at the end of file". This patch to eol extension simply adds trailing newline on commit. diff -r 23c2d7d25329 -r f33579435378 hgext/eol.py --- a/hgext/eol.py Fri Jul 01 22:53:58 2011 +0400 +++ b/hgext/eol.py Fri Jul 01 23:12:52 2011 +0400 @@ -106,6 +106,8 @@ return s if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): return s + if ui.configbool('eol', 'fix-trailing-newline', False) and s and s[-1] != '\n': + s = s + '\n' return eolre.sub('\n', s) def tocrlf(s, params, ui, **kwargs): @@ -114,6 +116,8 @@ return s if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): return s + if ui.configbool('eol', 'fix-trailing-newline', False) and s and s[-1] != '\n': + s = s + '\n' return eolre.sub('\r\n', s) def isbinary(s, params): diff -r 23c2d7d25329 -r f33579435378 tests/test-eol.t --- a/tests/test-eol.t Fri Jul 01 22:53:58 2011 +0400 +++ b/tests/test-eol.t Fri Jul 01 23:12:52 2011 +0400 @@ -463,3 +463,60 @@ > EOF $ hg commit -m 'consistent' + +Test trailing newline + + $ cat >> $HGRCPATH < [extensions] + > eol= + > EOF + +setup repository + + $ cd $TESTTMP + $ hg init trailing + $ cd trailing + $ cat > .hgeol < [patterns] + > **.txt = native + > [eol] + > fix-trailing-newline = False + > EOF + +add text without trailing newline + + $ printf "first\nsecond" > a.txt + $ hg commit --addremove -m 'checking in' + adding .hgeol + adding a.txt + $ rm a.txt + $ hg update -C -q + $ cat a.txt + first + second (no-eol) + + $ cat > .hgeol < [patterns] + > **.txt = native + > [eol] + > fix-trailing-newline = True + > EOF + $ printf "third\nfourth" > a.txt + $ hg commit -m 'checking in with newline fix' + $ rm a.txt + $ hg update -C -q + $ cat a.txt + third + fourth + +append a line without trailing newline + + $ printf "fifth" >> a.txt + $ hg commit -m 'adding another line line' + $ rm a.txt + $ hg update -C -q + $ cat a.txt + third + fourth + fifth +