From ad38c0dfadc0fc68ed6213c75541fe06c7caca2f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 24 Jun 2011 11:59:34 -0400 Subject: better setup of git-annex branch pushing on upgrade --- Branch.hs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'Branch.hs') diff --git a/Branch.hs b/Branch.hs index fad024550..3f5e0ee1e 100644 --- a/Branch.hs +++ b/Branch.hs @@ -11,7 +11,10 @@ module Branch ( get, change, commit, - files + files, + refExists, + hasOrigin, + name ) where import Control.Monad (unless, when, liftM) @@ -44,6 +47,10 @@ name = "git-annex" fullname :: String fullname = "refs/heads/" ++ name +{- Branch's name in origin. -} +originname :: String +originname = "origin/" ++ name + {- Converts a fully qualified git ref into a short version for human - consumptiom. -} shortref :: String -> String @@ -114,20 +121,14 @@ getCache file = getState >>= handle {- Creates the branch, if it does not already exist. -} create :: Annex () create = do - exists <- refexists fullname + exists <- refExists fullname unless exists $ do g <- Annex.gitRepo - inorigin <- refexists origin - if inorigin - then liftIO $ Git.run g "branch" [Param name, Param origin] + e <- hasOrigin + if e + then liftIO $ Git.run g "branch" [Param name, Param originname] else withIndex' True $ liftIO $ GitUnionMerge.commit g "branch created" fullname [] - where - origin = "origin/" ++ name - refexists ref = do - g <- Annex.gitRepo - liftIO $ Git.runBool g "show-ref" - [Param "--verify", Param "-q", Param ref] {- Stages the journal, and commits staged changes to the branch. -} commit :: String -> Annex () @@ -164,6 +165,17 @@ update = do Annex.changeState $ \s -> s { Annex.branchstate = state { branchUpdated = True } } invalidateCache +{- Does origin/git-annex exist? -} +hasOrigin :: Annex Bool +hasOrigin = refExists originname + +{- Checks if a git ref exists. -} +refExists :: String -> Annex Bool +refExists ref = do + g <- Annex.gitRepo + liftIO $ Git.runBool g "show-ref" + [Param "--verify", Param "-q", Param ref] + {- Ensures that a given ref has been merged into the index. -} updateRef :: String -> Annex (Maybe String) updateRef ref -- cgit v1.2.3