2018-08-28 14:26:51 +00:00
|
|
|
{- Git smudge filter configuration
|
|
|
|
-
|
|
|
|
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2018-08-28 14:26:51 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Config.Smudge where
|
|
|
|
|
|
|
|
import Annex.Common
|
|
|
|
import qualified Annex
|
|
|
|
import qualified Git
|
|
|
|
import qualified Git.Command
|
|
|
|
import Config
|
|
|
|
|
|
|
|
configureSmudgeFilter :: Annex ()
|
2018-08-29 13:20:25 +00:00
|
|
|
configureSmudgeFilter = unlessM (fromRepo Git.repoIsLocalBare) $ do
|
2018-08-28 14:26:51 +00:00
|
|
|
-- If this is run in a newly cloned repository, git may not have
|
|
|
|
-- cached file information in the index yet, and so after
|
|
|
|
-- configuring the clean filter, the next git status would want to
|
|
|
|
-- run it on every file. That is expensive and can also result in
|
|
|
|
-- unexpected changes when the file is checked into git or annex
|
|
|
|
-- counter to the annex.largefiles configuration.
|
|
|
|
-- Avoid that problem by running git status now.
|
|
|
|
inRepo $ Git.Command.runQuiet [Param "status", Param "--porcelain"]
|
|
|
|
|
2019-03-18 18:12:13 +00:00
|
|
|
setConfig (ConfigKey "filter.annex.smudge") "git-annex smudge -- %f"
|
|
|
|
setConfig (ConfigKey "filter.annex.clean") "git-annex smudge --clean -- %f"
|
2018-08-28 14:26:51 +00:00
|
|
|
lf <- Annex.fromRepo Git.attributesLocal
|
|
|
|
gf <- Annex.fromRepo Git.attributes
|
|
|
|
lfs <- readattr lf
|
|
|
|
gfs <- readattr gf
|
|
|
|
liftIO $ unless ("filter=annex" `isInfixOf` (lfs ++ gfs)) $ do
|
|
|
|
createDirectoryIfMissing True (takeDirectory lf)
|
|
|
|
writeFile lf (lfs ++ "\n" ++ stdattr)
|
|
|
|
where
|
|
|
|
readattr = liftIO . catchDefaultIO "" . readFileStrict
|
|
|
|
stdattr = unlines
|
|
|
|
[ "* filter=annex"
|
|
|
|
, ".* !filter"
|
|
|
|
]
|