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 import qualified GitRepo as Git
-- command-line flags -- command-line flags
data Flag = Force | NeedCommit data Flag = Force | NoCommit | NeedCommit
deriving (Eq, Read, Show) deriving (Eq, Read, Show)
-- git-annex's runtime state type doesn't really belong here, -- git-annex's runtime state type doesn't really belong here,

View file

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

View file

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

3
TODO
View file

@ -5,6 +5,9 @@
* how to handle git mv file? * 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 * Support for remote git repositories (ssh:// specifically can be made to
work, although the other end probably needs to have git-annex installed..) work, although the other end probably needs to have git-annex installed..)