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.Lock
import qualified Command.PreCommit import qualified Command.PreCommit
import qualified Command.Find import qualified Command.Find
import qualified Command.Uninit
subCmds :: [SubCommand] subCmds :: [SubCommand]
subCmds = subCmds =
@ -55,6 +56,8 @@ subCmds =
"initialize git-annex with repository description" "initialize git-annex with repository description"
, SubCommand "unannex" path Command.Unannex.seek , SubCommand "unannex" path Command.Unannex.seek
"undo accidential add command" "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 , SubCommand "pre-commit" path Command.PreCommit.seek
"run by git pre-commit hook" "run by git pre-commit hook"
, SubCommand "fromkey" key Command.FromKey.seek , SubCommand "fromkey" key Command.FromKey.seek

View file

@ -18,6 +18,7 @@ import UUID
import Version import Version
import Messages import Messages
import Locations import Locations
import Types
seek :: [SubCmdSeek] seek :: [SubCmdSeek]
seek = [withString start] seek = [withString start]
@ -36,8 +37,8 @@ perform description = do
u <- getUUID g u <- getUUID g
describeUUID u description describeUUID u description
setVersion setVersion
liftIO $ gitAttributes g liftIO $ gitAttributesWrite g
liftIO $ gitPreCommitHook g gitPreCommitHookWrite g
return $ Just cleanup return $ Just cleanup
cleanup :: SubCmdCleanup cleanup :: SubCmdCleanup
@ -50,8 +51,8 @@ cleanup = do
{- configure git to use union merge driver on state files, if it is not {- configure git to use union merge driver on state files, if it is not
- already -} - already -}
gitAttributes :: Git.Repo -> IO () gitAttributesWrite :: Git.Repo -> IO ()
gitAttributes repo = do gitAttributesWrite repo = do
exists <- doesFileExist attributes exists <- doesFileExist attributes
if not exists if not exists
then do then do
@ -63,24 +64,34 @@ gitAttributes repo = do
appendFile attributes $ attrLine ++ "\n" appendFile attributes $ attrLine ++ "\n"
commit commit
where where
attrLine = stateLoc ++ "*.log merge=union"
attributes = Git.attributes repo attributes = Git.attributes repo
commit = do commit = do
Git.run repo ["add", attributes] Git.run repo ["add", attributes]
Git.run repo ["commit", "-m", "git-annex setup", Git.run repo ["commit", "-m", "git-annex setup",
attributes] attributes]
attrLine :: String
attrLine = stateLoc ++ "*.log merge=union"
{- set up a git pre-commit hook, if one is not already present -} {- set up a git pre-commit hook, if one is not already present -}
gitPreCommitHook :: Git.Repo -> IO () gitPreCommitHookWrite :: Git.Repo -> Annex ()
gitPreCommitHook repo = do gitPreCommitHookWrite repo = do
let hook = Git.workTree repo ++ "/" ++ Git.gitDir repo ++ exists <- liftIO $ doesFileExist hook
"/hooks/pre-commit"
exists <- doesFileExist hook
if exists if exists
then putStrLn $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring" then warning $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
else do else liftIO $ do
writeFile hook $ "#!/bin/sh\n" ++ writeFile hook preCommitScript
"# automatically configured by git-annex\n" ++
"git annex pre-commit .\n"
p <- getPermissions hook p <- getPermissions hook
setPermissions hook $ p {executable = True} 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 ( module Utility (
hGetContentsStrict, hGetContentsStrict,
readFileStrict,
parentDir, parentDir,
absPath, absPath,
relPathCwdToDir, relPathCwdToDir,
@ -34,6 +35,10 @@ import Foreign (complement)
hGetContentsStrict :: Handle -> IO String hGetContentsStrict :: Handle -> IO String
hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s 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 "" -} {- Returns the parent directory of a path. Parent of / is "" -}
parentDir :: String -> String parentDir :: String -> String
parentDir dir = parentDir dir =

1
debian/changelog vendored
View file

@ -5,6 +5,7 @@ git-annex (0.11) UNRELEASED; urgency=low
* Added remote.annex-rsync-options. * Added remote.annex-rsync-options.
* Avoid deleting temp files when rsync fails. * Avoid deleting temp files when rsync fails.
* Improve detection of version 0 repos. * Improve detection of version 0 repos.
* Add uninit subcommand. Closes: #605749
-- Joey Hess <joeyh@debian.org> Thu, 02 Dec 2010 16:54:12 -0400 -- 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 any more. In that case you should use `git annex drop` instead, and you
can also `git rm` the file. 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 ...] * fix [path ...]
Fixes up symlinks that have become broken to again point to annexed content. Fixes up symlinks that have become broken to again point to annexed content.