add --no-commit option

This commit is contained in:
Joey Hess 2010-10-16 19:43:32 -04:00
parent b3e5590fb2
commit be5b1defeb
4 changed files with 32 additions and 13 deletions

View file

@ -11,7 +11,7 @@ import Data.String.Utils
import qualified GitRepo as Git
-- command-line flags
data Flag = Force | NeedCommit
data Flag = Force | NoCommit | NeedCommit
deriving (Eq, Read, Show)
-- git-annex's runtime state type doesn't really belong here,

View file

@ -32,7 +32,8 @@ data Command = Command {
}
cmds :: [Command]
cmds = [ (Command "add" addCmd FilesNotInGit)
cmds = [
(Command "add" addCmd FilesNotInGit)
, (Command "get" getCmd FilesInGit)
, (Command "drop" dropCmd FilesInGit)
, (Command "push" pushCmd RepoName)
@ -41,6 +42,11 @@ cmds = [ (Command "add" addCmd FilesNotInGit)
, (Command "describe" describeCmd SingleString)
]
options = [
Option ['f'] ["force"] (NoArg Force) "allow actions that may loose annexed data"
, Option ['N'] ["no-commit"] (NoArg NoCommit) "do not stage or commit changes"
]
{- Finds the type of parameters a command wants, from among the passed
- parameter list. -}
findWanted :: CmdWants -> [String] -> Git.Repo -> IO [String]
@ -75,7 +81,6 @@ parseCmd argv state = do
lookupCmd cmd = filter (\c -> cmd == cmdname c) cmds
header = "Usage: git-annex [" ++
(join "|" $ map cmdname cmds) ++ "] ..."
options = [ Option ['f'] ["force"] (NoArg Force) "allow actions that may loose annexed data" ]
{- Annexes a file, storing it in a backend, and then moving it into
- the annex directory and setting up the symlink pointing to its content. -}
@ -89,7 +94,7 @@ addCmd file = inBackend file err $ do
Nothing -> error $ "no backend could store: " ++ file
Just (key, backend) -> do
logStatus key ValuePresent
liftIO $ setup g key link
setup g key link
where
err = error $ "already annexed " ++ file
checkLegal file = do
@ -106,12 +111,16 @@ addCmd file = inBackend file err $ do
setup g key link = do
let dest = annexLocation g key
let reldest = annexLocationRelative g key
createDirectoryIfMissing True (parentDir dest)
renameFile file dest
createSymbolicLink (link ++ reldest) file
Git.run g ["add", file]
Git.run g ["commit", "-m",
("git-annex annexed " ++ file), file]
liftIO $ createDirectoryIfMissing True (parentDir dest)
liftIO $ renameFile file dest
liftIO $ createSymbolicLink (link ++ reldest) file
nocommit <- Annex.flagIsSet NoCommit
if (not nocommit)
then do
liftIO $ Git.run g ["add", file]
liftIO $ Git.run g ["commit", "-m",
("git-annex annexed " ++ file), file]
else return ()
{- Inverse of addCmd. -}
unannexCmd :: FilePath -> Annex ()
@ -192,7 +201,10 @@ describeCmd description = do
u <- getUUID g
describeUUID u description
log <- uuidLog
liftIO $ Git.run g ["add", log]
nocommit <- Annex.flagIsSet NoCommit
if (not nocommit)
then liftIO $ Git.run g ["add", log]
else return ()
Annex.flagChange NeedCommit True
liftIO $ putStrLn "description set"
@ -202,7 +214,10 @@ logStatus key status = do
g <- Annex.gitRepo
u <- getUUID g
f <- liftIO $ logChange g key u status
liftIO $ Git.run g ["add", f]
nocommit <- Annex.flagIsSet NoCommit
if (not nocommit)
then liftIO $ Git.run g ["add", f]
else return ()
Annex.flagChange NeedCommit True
inBackend file yes no = do

View file

@ -24,8 +24,9 @@ startup flags = do
shutdown :: Annex ()
shutdown = do
g <- Annex.gitRepo
nocommit <- Annex.flagIsSet NoCommit
needcommit <- Annex.flagIsSet NeedCommit
if (needcommit)
if (needcommit && not nocommit)
then liftIO $ Git.run g ["commit", "-q", "-m",
"git-annex log update", gitStateDir g]
else return ()

3
TODO
View file

@ -5,6 +5,9 @@
* how to handle git mv file?
* how to handle git rm file? (should try to drop keys that have no
referring file, if it seems safe..)
* Support for remote git repositories (ssh:// specifically can be made to
work, although the other end probably needs to have git-annex installed..)