Browse files

Ensure that every page ends with a newline.

This avoids "No newline at eof" messages in diffs.
  • Loading branch information...
1 parent 9fd0caf commit 87e7c5db1734e05e54266a24f70a736660d5ac02 @jgm committed Nov 8, 2008
Showing with 3 additions and 2 deletions.
  1. +3 −2 Gitit.hs
View
5 Gitit.hs
@@ -604,20 +604,21 @@ updatePage page params = do
then error "Page exceeds maximum size."
else return ()
currentSHA1 <- gitGetSHA1 (pathForPage page) >>= return . fromMaybe ""
+ -- ensure that every file has a newline at the end, to avoid "No newline at eof" messages in diffs
+ let editedText' = if null editedText || last editedText == '\n' then editedText else editedText ++ "\n"
-- check SHA1 in case page has been modified, merge
if currentSHA1 == oldSHA1
then do
let dir' = takeDirectory page
liftIO $ createDirectoryIfMissing True ((repositoryPath cfg) </> dir')
- liftIO $ writeFile ((repositoryPath cfg) </> pathForPage page) editedText
+ liftIO $ writeFile ((repositoryPath cfg) </> pathForPage page) editedText'
gitCommit (pathForPage page) (author, email) logMsg
seeOther (urlForPage page) $ toResponse $ p << "Page updated"
else do -- there have been conflicting changes
original <- gitCatFile oldSHA1 (pathForPage page) >>= return . fromJust
latest <- gitCatFile currentSHA1 (pathForPage page) >>= return . fromJust
let pagePath = repositoryPath cfg </> pathForPage page
let [textTmp, originalTmp, latestTmp] = map (pagePath ++) [".edited",".original",".latest"]
- let editedText' = if null editedText || last editedText == '\n' then editedText else editedText ++ "\n"
liftIO $ writeFile textTmp editedText'
liftIO $ writeFile originalTmp original
liftIO $ writeFile latestTmp latest

0 comments on commit 87e7c5d

Please sign in to comment.