update for git-annex branch

stop changing gitattributes on init

create git-annex branch on init

ugly special case for init in a bare repository goes away, yay!

git annex init is also faster, at least in a large existing repo, as
it does not need to run the slow 'git add'
This commit is contained in:
Joey Hess 2011-06-22 16:03:26 -04:00
parent 5c706d1ec4
commit e0bd9d43a2
2 changed files with 6 additions and 59 deletions

View file

@ -11,7 +11,6 @@ import Command
import qualified Remote import qualified Remote
import UUID import UUID
import Messages import Messages
import qualified Command.Init
command :: [Command] command :: [Command]
command = [repoCommand "describe" (paramPair paramRemote paramDesc) seek command = [repoCommand "describe" (paramPair paramRemote paramDesc) seek
@ -34,4 +33,4 @@ start ws = notBareRepo $ do
perform :: UUID -> String -> CommandPerform perform :: UUID -> String -> CommandPerform
perform u description = do perform u description = do
describeUUID u description describeUUID u description
next $ Command.Init.cleanup next $ return True

View file

@ -15,6 +15,7 @@ import System.FilePath
import Command import Command
import qualified Annex import qualified Annex
import qualified GitRepo as Git import qualified GitRepo as Git
import qualified Branch
import UUID import UUID
import Version import Version
import Messages import Messages
@ -29,7 +30,6 @@ command = [repoCommand "init" paramDesc seek
seek :: [CommandSeek] seek :: [CommandSeek]
seek = [withWords start] seek = [withWords start]
{- Stores description for the repository etc. -}
start :: CommandStartWords start :: CommandStartWords
start ws = do start ws = do
when (null description) $ when (null description) $
@ -41,65 +41,13 @@ start ws = do
perform :: String -> CommandPerform perform :: String -> CommandPerform
perform description = do perform description = do
Branch.create
g <- Annex.gitRepo g <- Annex.gitRepo
u <- getUUID g u <- getUUID g
setVersion setVersion
if Git.repoIsLocalBare g describeUUID u description
then do gitPreCommitHookWrite g
showLongNote $ next $ return True
"This is a bare repository, so its description cannot be committed.\n" ++
"To record the description, run this command in a clone of this repository:\n" ++
" git annex describe " ++ show u ++ " " ++ show description ++ "\n\n"
next $ return True
else do
describeUUID u description
liftIO $ gitAttributesWrite g
gitPreCommitHookWrite g
next cleanup
cleanup :: CommandCleanup
cleanup = do
g <- Annex.gitRepo
logfile <- uuidLog
liftIO $ Git.run g "add" [File logfile]
liftIO $ Git.run g "commit"
[ Params "-q -m"
, Param "git annex repository description"
, File logfile
]
return True
{- configure git to use union merge driver on state files, if it is not
- already -}
gitAttributesWrite :: Git.Repo -> IO ()
gitAttributesWrite repo = do
exists <- doesFileExist attributes
if not exists
then do
safeWriteFile attributes $ unlines attrLines
commit
else do
content <- readFile attributes
let present = lines content
let missing = filter (\l -> not $ l `elem` present) attrLines
unless (null missing) $ do
appendFile attributes $ unlines missing
commit
where
attributes = Git.attributes repo
commit = do
Git.run repo "add" [Param attributes]
Git.run repo "commit"
[ Params "-q -m"
, Param "git-annex setup"
, Param attributes
]
attrLines :: [String]
attrLines =
[ stateDir </> "*.log merge=union"
, stateDir </> "*/*/*.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 -}
gitPreCommitHookWrite :: Git.Repo -> Annex () gitPreCommitHookWrite :: Git.Repo -> Annex ()