Add uninit subcommand. Closes: #605749

This commit is contained in:
Joey Hess 2010-12-03 00:33:41 -04:00
parent 6f932a0963
commit 57305570eb
6 changed files with 100 additions and 15 deletions

View file

@ -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

View file

@ -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"

59
Command/Uninit.hs Normal file
View file

@ -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

View file

@ -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 =

1
debian/changelog vendored
View file

@ -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

View file

@ -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.