Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep .git when cleaning destinationDirectory #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/Hakyll/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ module Hakyll.Commands
--------------------------------------------------------------------------------
import Control.Applicative
import Control.Concurrent
import Control.Monad (void)
import Control.Monad (void, forM_)
import System.Exit (ExitCode, exitWith)
import System.IO.Error (catchIOError)
import System.Directory (doesDirectoryExist, getDirectoryContents, removeFile)
import System.FilePath ((</>), pathSeparator)

--------------------------------------------------------------------------------
import qualified Hakyll.Check as Check
Expand Down Expand Up @@ -56,14 +58,33 @@ check config logger check' = Check.check config logger check' >>= exitWith
-- | Remove the output directories
clean :: Configuration -> Logger -> IO ()
clean conf logger = do
remove $ destinationDirectory conf
removeGitFriendly $ destinationDirectory conf
remove $ storeDirectory conf
remove $ tmpDirectory conf
where
remove dir = do
Logger.header logger $ "Removing " ++ dir ++ "..."
removeDirectory dir

removeGitFriendly dir = do
Logger.header logger $ "Removing " ++ dir ++ " (keeping potential .git)..."
containsGitRepo <- doesDirectoryExist (dir ++ [pathSeparator] ++ ".git")
if containsGitRepo
then do
nestedFilePaths <- getNonRecursiveDirContents dir
forM_ nestedFilePaths $ \nestedFilePath -> removeFilePath (dir </> nestedFilePath)
else do
remove dir

getNonRecursiveDirContents dir = do
names <- getDirectoryContents dir
return $ filter (`notElem` [".", "..", ".git"]) names

removeFilePath filePath = do
isDirectory <- doesDirectoryExist filePath
if isDirectory
then removeDirectory filePath
else removeFile filePath

--------------------------------------------------------------------------------
-- | Preview the site
Expand Down