summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-11-02 15:29:38 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-11-02 15:29:38 -0400
commit8cff4865d3bee469742538c23d1e16e67cadd9cb (patch)
treec1bc15a14fe51b0f4a69e3fe5e33e2858ac9a88c
parent95e946a21e1960c9dcf63ad579c58434746295b2 (diff)
sync: Work even when the local git repository is new and empty, with no master branch.
-rw-r--r--Command/Merge.hs3
-rw-r--r--Command/Sync.hs29
-rw-r--r--debian/changelog2
3 files changed, 20 insertions, 14 deletions
diff --git a/Command/Merge.hs b/Command/Merge.hs
index 5d6b2ffd2..31db7a99f 100644
--- a/Command/Merge.hs
+++ b/Command/Merge.hs
@@ -34,6 +34,5 @@ mergeBranch = do
mergeSynced :: CommandStart
mergeSynced = do
- branch <- inRepo Git.Branch.current
prepMerge
- maybe stop mergeLocal branch
+ mergeLocal =<< inRepo Git.Branch.current
diff --git a/Command/Sync.hs b/Command/Sync.hs
index 1fbd9c028..2a6f340e7 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -45,13 +45,15 @@ seek rs = do
prepMerge
-- There may not be a branch checked out until after the commit,
- -- so only look it up once needed, and only look it up once.
+ -- or perhaps after it gets merged from the remote.
+ -- So only look it up once it's needed, and if once there is a
+ -- branch, cache it.
mvar <- liftIO newEmptyMVar
let getbranch = ifM (liftIO $ isEmptyMVar mvar)
( do
- branch <- fromMaybe (error "no branch is checked out")
- <$> inRepo Git.Branch.current
- liftIO $ putMVar mvar branch
+ branch <- inRepo Git.Branch.current
+ when (isJust branch) $
+ liftIO $ putMVar mvar branch
return branch
, liftIO $ readMVar mvar
)
@@ -116,8 +118,9 @@ commit = next $ next $ ifM isDirect
_ <- inRepo $ tryIO . Git.Command.runQuiet params
return True
-mergeLocal :: Git.Ref -> CommandStart
-mergeLocal branch = go =<< needmerge
+mergeLocal :: Maybe Git.Ref -> CommandStart
+mergeLocal Nothing = stop
+mergeLocal (Just branch) = go =<< needmerge
where
syncbranch = syncBranch branch
needmerge = ifM isBareRepo
@@ -132,8 +135,9 @@ mergeLocal branch = go =<< needmerge
showStart "merge" $ Git.Ref.describe syncbranch
next $ next $ mergeFrom syncbranch
-pushLocal :: Git.Ref -> CommandStart
-pushLocal branch = do
+pushLocal :: Maybe Git.Ref -> CommandStart
+pushLocal Nothing = stop
+pushLocal (Just branch) = do
inRepo $ updateBranch $ syncBranch branch
stop
@@ -147,13 +151,13 @@ updateBranch syncbranch g =
, Param $ show $ Git.Ref.base syncbranch
] g
-pullRemote :: Remote -> Git.Ref -> CommandStart
+pullRemote :: Remote -> Maybe Git.Ref -> CommandStart
pullRemote remote branch = do
showStart "pull" (Remote.name remote)
next $ do
showOutput
stopUnless fetch $
- next $ mergeRemote remote (Just branch)
+ next $ mergeRemote remote branch
where
fetch = inRepo $ Git.Command.runBool
[Param "fetch", Param $ Remote.name remote]
@@ -175,8 +179,9 @@ mergeRemote remote b = case b of
branchlist Nothing = []
branchlist (Just branch) = [branch, syncBranch branch]
-pushRemote :: Remote -> Git.Ref -> CommandStart
-pushRemote remote branch = go =<< needpush
+pushRemote :: Remote -> Maybe Git.Ref -> CommandStart
+pushRemote _remote Nothing = stop
+pushRemote remote (Just branch) = go =<< needpush
where
needpush = anyM (newer remote) [syncBranch branch, Annex.Branch.name]
go False = stop
diff --git a/debian/changelog b/debian/changelog
index 6c743e19a..3f37a4d37 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,8 @@ git-annex (4.20131102) UNRELEASED; urgency=low
* Improve local pairing behavior when two computers both try to start
the pairing process separately.
+ * sync: Work even when the local git repository is new and empty,
+ with no master branch.
-- Joey Hess <joeyh@debian.org> Sat, 02 Nov 2013 14:54:36 -0400