git-annex/Command/TweakFetch.hs

35 lines
973 B
Haskell
Raw Normal View History

add tweak-fetch command, for use in the tweak-fetch hook tweak-fetch is a new git hook I have developed (not yet accepted into git, but looking bright). Amoung other things, the hook can be used to observe what is being fetched, notice remote git-annex branches that might be updated, and merge them into the git-annex branch. This will solve problems where users do a git pull, immediately followed by a push, and it refuses to push because their git-annex branch is diverged, and they neither ran git annex merge by hand, nor ran other git-annex commands that auto-merge. The tweak-fetch is written by git annex init. Of course, existing repositories won't have it, which is ok, because git-annex still automatically does a merge if changed branches have appeared. Indeed, it will always need to do that check, as long as it needs to support support git-annex branches that might be updated by other means. Eventually though, I will want to ensure all repositories have the tweak-fetch hook. Perhaps a minor verison upgrade to ensure it is added? A subtlety of the hook is that when it's run, the remote tracking refs have not yet been updated. So Annex.Branch.updateTo has to be careful to only use the sha1 that was fetched, not the branch name. The branch name is only used in the commit message. The other tricky thing is that git tweak-fetch hook should *only* output lines in a specific format, and git will be unhappy if it also outputs status messages, etc. So those messages are sent to stderr.
2011-12-26 14:25:37 -04:00
{- git-annex command
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.TweakFetch where
import Common
import Command
import qualified Git.TweakFetch
import qualified Annex.Branch
def :: [Command]
def = [command "tweak-fetch" paramNothing seek "run by git tweak-fetch hook"]
seek :: [CommandSeek]
seek = [ withNothing start]
start :: CommandStart
start = do
-- First, pass the hook's input through to its output, unchanged.
fetched <- liftIO $ Git.TweakFetch.runHook return
-- If one of the fetched refs is going to be stored on a git-annex
-- tracking branch, then merge in the new sha for that ref.
let tomerge = filter siblings fetched
unless (null tomerge) $ Annex.Branch.updateTo $ map topairs tomerge
stop
where
siblings f = suffix `isSuffixOf` (show $ Git.TweakFetch.local f)
suffix = "/" ++ show Annex.Branch.name
topairs f = (Git.TweakFetch.sha f, Git.TweakFetch.local f)