diff options
author | Joey Hess <joey@kitenet.net> | 2010-12-03 00:33:41 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-12-03 00:33:41 -0400 |
commit | 57305570eb5fce88c743ca4f7ff127c7ef582310 (patch) | |
tree | e2f590eca8f1efef4bc1ec6bcfe99f8e0474e909 | |
parent | 6f932a0963341b235f262c43982cc138f443f2de (diff) |
Add uninit subcommand. Closes: #605749
-rw-r--r-- | CmdLine.hs | 3 | ||||
-rw-r--r-- | Command/Init.hs | 41 | ||||
-rw-r--r-- | Command/Uninit.hs | 59 | ||||
-rw-r--r-- | Utility.hs | 5 | ||||
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | doc/git-annex.mdwn | 6 |
6 files changed, 100 insertions, 15 deletions
diff --git a/CmdLine.hs b/CmdLine.hs index 837420786..0903cc1fb 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -32,6 +32,7 @@ import qualified Command.Unlock import qualified Command.Lock import qualified Command.PreCommit import qualified Command.Find +import qualified Command.Uninit subCmds :: [SubCommand] subCmds = @@ -55,6 +56,8 @@ subCmds = "initialize git-annex with repository description" , SubCommand "unannex" path Command.Unannex.seek "undo accidential add command" + , SubCommand "uninit" path Command.Uninit.seek + "de-initialize git-annex and clean out repository" , SubCommand "pre-commit" path Command.PreCommit.seek "run by git pre-commit hook" , SubCommand "fromkey" key Command.FromKey.seek diff --git a/Command/Init.hs b/Command/Init.hs index eb5c58696..e19849ba3 100644 --- a/Command/Init.hs +++ b/Command/Init.hs @@ -18,6 +18,7 @@ import UUID import Version import Messages import Locations +import Types seek :: [SubCmdSeek] seek = [withString start] @@ -36,8 +37,8 @@ perform description = do u <- getUUID g describeUUID u description setVersion - liftIO $ gitAttributes g - liftIO $ gitPreCommitHook g + liftIO $ gitAttributesWrite g + gitPreCommitHookWrite g return $ Just cleanup cleanup :: SubCmdCleanup @@ -50,8 +51,8 @@ cleanup = do {- configure git to use union merge driver on state files, if it is not - already -} -gitAttributes :: Git.Repo -> IO () -gitAttributes repo = do +gitAttributesWrite :: Git.Repo -> IO () +gitAttributesWrite repo = do exists <- doesFileExist attributes if not exists then do @@ -63,24 +64,34 @@ gitAttributes repo = do appendFile attributes $ attrLine ++ "\n" commit where - attrLine = stateLoc ++ "*.log merge=union" attributes = Git.attributes repo commit = do Git.run repo ["add", attributes] Git.run repo ["commit", "-m", "git-annex setup", attributes] +attrLine :: String +attrLine = stateLoc ++ "*.log merge=union" + {- set up a git pre-commit hook, if one is not already present -} -gitPreCommitHook :: Git.Repo -> IO () -gitPreCommitHook repo = do - let hook = Git.workTree repo ++ "/" ++ Git.gitDir repo ++ - "/hooks/pre-commit" - exists <- doesFileExist hook +gitPreCommitHookWrite :: Git.Repo -> Annex () +gitPreCommitHookWrite repo = do + exists <- liftIO $ doesFileExist hook if exists - then putStrLn $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring" - else do - writeFile hook $ "#!/bin/sh\n" ++ - "# automatically configured by git-annex\n" ++ - "git annex pre-commit .\n" + then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring" + else liftIO $ do + writeFile hook preCommitScript p <- getPermissions hook setPermissions hook $ p {executable = True} + where + hook = preCommitHook repo + +preCommitHook :: Git.Repo -> FilePath +preCommitHook repo = + Git.workTree repo ++ "/" ++ Git.gitDir repo ++ "/hooks/pre-commit" + +preCommitScript :: String +preCommitScript = + "#!/bin/sh\n" ++ + "# automatically configured by git-annex\n" ++ + "git annex pre-commit .\n" diff --git a/Command/Uninit.hs b/Command/Uninit.hs new file mode 100644 index 000000000..fcb77a92b --- /dev/null +++ b/Command/Uninit.hs @@ -0,0 +1,59 @@ +{- git-annex command + - + - Copyright 2010 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.Uninit where + +import Control.Monad.State (liftIO) +import Control.Monad (when) +import System.Directory + +import Command +import Messages +import Types +import Utility +import qualified GitRepo as Git +import qualified Annex +import qualified Command.Unannex +import qualified Command.Init + +seek :: [SubCmdSeek] +seek = [withAll withFilesInGit Command.Unannex.start, withNothing start] + +start :: SubCmdStartNothing +start = do + showStart "uninit" "" + return $ Just $ perform + +perform :: SubCmdPerform +perform = do + g <- Annex.gitRepo + + gitPreCommitHookUnWrite g + liftIO $ gitAttributesUnWrite g + + return $ Just $ return True + +gitPreCommitHookUnWrite :: Git.Repo -> Annex () +gitPreCommitHookUnWrite repo = do + let hook = Command.Init.preCommitHook repo + hookexists <- liftIO $ doesFileExist hook + when hookexists $ do + c <- liftIO $ readFile hook + if c == Command.Init.preCommitScript + then liftIO $ removeFile hook + else warning $ "pre-commit hook (" ++ hook ++ + ") contents modified; not deleting." ++ + " Edit it to remove call to git annex." + +gitAttributesUnWrite :: Git.Repo -> IO () +gitAttributesUnWrite repo = do + let attributes = Git.attributes repo + attrexists <- doesFileExist attributes + when attrexists $ do + c <- readFileStrict attributes + writeFile attributes $ unlines $ + filter (/= Command.Init.attrLine) $ lines c diff --git a/Utility.hs b/Utility.hs index 0f7ce42aa..2447c95a0 100644 --- a/Utility.hs +++ b/Utility.hs @@ -7,6 +7,7 @@ module Utility ( hGetContentsStrict, + readFileStrict, parentDir, absPath, relPathCwdToDir, @@ -34,6 +35,10 @@ import Foreign (complement) hGetContentsStrict :: Handle -> IO String hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s +{- A version of readFile that is not lazy. -} +readFileStrict :: FilePath -> IO String +readFileStrict f = readFile f >>= \s -> length s `seq` return s + {- Returns the parent directory of a path. Parent of / is "" -} parentDir :: String -> String parentDir dir = diff --git a/debian/changelog b/debian/changelog index 9e378400c..b5ef4b5a0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ git-annex (0.11) UNRELEASED; urgency=low * Added remote.annex-rsync-options. * Avoid deleting temp files when rsync fails. * Improve detection of version 0 repos. + * Add uninit subcommand. Closes: #605749 -- Joey Hess <joeyh@debian.org> Thu, 02 Dec 2010 16:54:12 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index 63bc11eb7..66e8bbaa8 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -151,6 +151,12 @@ Many git-annex subcommands will stage changes for later `git commit` by you. any more. In that case you should use `git annex drop` instead, and you can also `git rm` the file. +* uninit + + Use this to stop using git annex. It will unannex every file in the + repository, and remove all of git-annex's other data, leaving you with a + git repository plus the previously annexed files. + * fix [path ...] Fixes up symlinks that have become broken to again point to annexed content. |