refactor
This commit is contained in:
parent
be5b1defeb
commit
c69e747d38
2 changed files with 23 additions and 18 deletions
20
Commands.hs
20
Commands.hs
|
@ -114,13 +114,7 @@ addCmd file = inBackend file err $ do
|
||||||
liftIO $ createDirectoryIfMissing True (parentDir dest)
|
liftIO $ createDirectoryIfMissing True (parentDir dest)
|
||||||
liftIO $ renameFile file dest
|
liftIO $ renameFile file dest
|
||||||
liftIO $ createSymbolicLink (link ++ reldest) file
|
liftIO $ createSymbolicLink (link ++ reldest) file
|
||||||
nocommit <- Annex.flagIsSet NoCommit
|
gitAdd file $ Just $ "git-annex annexed " ++ file
|
||||||
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. -}
|
{- Inverse of addCmd. -}
|
||||||
unannexCmd :: FilePath -> Annex ()
|
unannexCmd :: FilePath -> Annex ()
|
||||||
|
@ -201,11 +195,7 @@ describeCmd description = do
|
||||||
u <- getUUID g
|
u <- getUUID g
|
||||||
describeUUID u description
|
describeUUID u description
|
||||||
log <- uuidLog
|
log <- uuidLog
|
||||||
nocommit <- Annex.flagIsSet NoCommit
|
gitAdd log Nothing -- all logs are committed at end
|
||||||
if (not nocommit)
|
|
||||||
then liftIO $ Git.run g ["add", log]
|
|
||||||
else return ()
|
|
||||||
Annex.flagChange NeedCommit True
|
|
||||||
liftIO $ putStrLn "description set"
|
liftIO $ putStrLn "description set"
|
||||||
|
|
||||||
{- Updates the LocationLog when a key's presence changes. -}
|
{- Updates the LocationLog when a key's presence changes. -}
|
||||||
|
@ -214,11 +204,7 @@ 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
|
||||||
nocommit <- Annex.flagIsSet NoCommit
|
gitAdd f Nothing -- all logs are committed at end
|
||||||
if (not nocommit)
|
|
||||||
then liftIO $ Git.run g ["add", f]
|
|
||||||
else return ()
|
|
||||||
Annex.flagChange NeedCommit True
|
|
||||||
|
|
||||||
inBackend file yes no = do
|
inBackend file yes no = do
|
||||||
r <- liftIO $ Backend.lookupFile file
|
r <- liftIO $ Backend.lookupFile file
|
||||||
|
|
21
Core.hs
21
Core.hs
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
module Core where
|
module Core where
|
||||||
|
|
||||||
|
import Maybe
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import Control.Monad.State (liftIO)
|
import Control.Monad.State (liftIO)
|
||||||
|
@ -61,4 +62,22 @@ inAnnex key = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
liftIO $ doesFileExist $ annexLocation g key
|
liftIO $ doesFileExist $ annexLocation g key
|
||||||
|
|
||||||
{- -}
|
{- Adds, optionally also commits a file to git.
|
||||||
|
-
|
||||||
|
- All changes to the git repository should go through this function.
|
||||||
|
-
|
||||||
|
- This is careful to not rely on the index. It may have staged changes,
|
||||||
|
- so only use operations that avoid committing such changes.
|
||||||
|
-}
|
||||||
|
gitAdd :: FilePath -> Maybe String -> Annex ()
|
||||||
|
gitAdd file commitmessage = do
|
||||||
|
nocommit <- Annex.flagIsSet NoCommit
|
||||||
|
if (nocommit)
|
||||||
|
then Annex.flagChange NeedCommit True
|
||||||
|
else do
|
||||||
|
g <- Annex.gitRepo
|
||||||
|
liftIO $ Git.run g ["add", file]
|
||||||
|
if (isJust commitmessage)
|
||||||
|
then liftIO $ Git.run g ["commit", "-m",
|
||||||
|
(fromJust commitmessage), file]
|
||||||
|
else return ()
|
||||||
|
|
Loading…
Reference in a new issue