summaryrefslogtreecommitdiff
path: root/Branch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-17 14:14:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-17 14:44:31 -0400
commit56f6923ccbc6fb1932137b53458a4cece47e69b0 (patch)
treea2c9a949f2c6c5163551a76f4012e7606e3c1463 /Branch.hs
parent3b5f7221305ba6e768711d8326a01b78fb1e4f79 (diff)
Now "git annex init" only has to be run once
when a git repository is first being created. Clones will automatically notice that git-annex is in use and automatically perform a basic initalization. It's still recommended to run "git annex init" in any clones, to describe them.
Diffstat (limited to 'Branch.hs')
-rw-r--r--Branch.hs32
1 files changed, 24 insertions, 8 deletions
diff --git a/Branch.hs b/Branch.hs
index 35e305093..fd4ce4ced 100644
--- a/Branch.hs
+++ b/Branch.hs
@@ -14,6 +14,7 @@ module Branch (
files,
refExists,
hasOrigin,
+ hasSomeBranch,
name
) where
@@ -124,7 +125,7 @@ getCache file = getState >>= handle
{- Creates the branch, if it does not already exist. -}
create :: Annex ()
-create = unlessM (refExists fullname) $ do
+create = unlessM hasBranch $ do
g <- Annex.gitRepo
e <- hasOrigin
if e
@@ -154,19 +155,14 @@ update = do
-}
staged <- stageJournalFiles
- g <- Annex.gitRepo
- r <- liftIO $ Git.pipeRead g [Param "show-ref", Param name]
- let refs = map (last . words) (lines r)
+ refs <- siblingBranches
updated <- catMaybes `liftM` mapM updateRef refs
+ g <- Annex.gitRepo
unless (null updated && not staged) $ liftIO $
Git.commit g "update" fullname (fullname:updated)
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 :: GitRef -> Annex Bool
refExists ref = do
@@ -174,6 +170,26 @@ refExists ref = do
liftIO $ Git.runBool g "show-ref"
[Param "--verify", Param "-q", Param ref]
+{- Does the main git-annex branch exist? -}
+hasBranch :: Annex Bool
+hasBranch = refExists fullname
+
+{- Does origin/git-annex exist? -}
+hasOrigin :: Annex Bool
+hasOrigin = refExists originname
+
+{- Does the git-annex branch or a foo/git-annex branch exist? -}
+hasSomeBranch :: Annex Bool
+hasSomeBranch = liftM (not . null) siblingBranches
+
+{- List of all git-annex branches, including the main one and any
+ - from remotes. -}
+siblingBranches :: Annex [String]
+siblingBranches = do
+ g <- Annex.gitRepo
+ r <- liftIO $ Git.pipeRead g [Param "show-ref", Param name]
+ return $ map (last . words) (lines r)
+
{- Ensures that a given ref has been merged into the index. -}
updateRef :: GitRef -> Annex (Maybe String)
updateRef ref