2017-02-17 18:04:43 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2017 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.PostReceive where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Annex
|
|
|
|
import Git.Types
|
2017-02-17 19:21:39 +00:00
|
|
|
import Annex.UpdateInstead
|
2018-10-19 19:17:48 +00:00
|
|
|
import Annex.CurrentBranch
|
|
|
|
import Command.Sync (mergeLocal, prepMerge, mergeConfig)
|
2017-02-17 18:04:43 +00:00
|
|
|
|
2017-02-23 22:37:02 +00:00
|
|
|
-- This does not need to modify the git-annex branch to update the
|
|
|
|
-- work tree, but auto-initialization might change the git-annex branch.
|
|
|
|
-- Since it would be surprising for a post-receive hook to make such a
|
|
|
|
-- change, that's prevented by noCommit.
|
2017-02-17 18:04:43 +00:00
|
|
|
cmd :: Command
|
2017-02-23 22:37:02 +00:00
|
|
|
cmd = noCommit $
|
|
|
|
command "post-receive" SectionPlumbing
|
|
|
|
"run by git post-receive hook"
|
|
|
|
paramNothing
|
|
|
|
(withParams seek)
|
2017-02-17 18:04:43 +00:00
|
|
|
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
|
|
seek _ = whenM needUpdateInsteadEmulation $ do
|
|
|
|
fixPostReceiveHookEnv
|
2017-02-17 19:21:39 +00:00
|
|
|
commandAction updateInsteadEmulation
|
2017-02-17 18:04:43 +00:00
|
|
|
|
|
|
|
{- When run by the post-receive hook, the cwd is the .git directory,
|
|
|
|
- and GIT_DIR=. It's not clear why git does this.
|
|
|
|
-
|
|
|
|
- Fix up from that unusual situation, so that git commands
|
|
|
|
- won't try to treat .git as the work tree. -}
|
|
|
|
fixPostReceiveHookEnv :: Annex ()
|
|
|
|
fixPostReceiveHookEnv = do
|
|
|
|
g <- Annex.gitRepo
|
|
|
|
case location g of
|
|
|
|
Local { gitdir = ".", worktree = Just "." } ->
|
|
|
|
Annex.adjustGitRepo $ \g' -> pure $ g'
|
|
|
|
{ location = (location g')
|
|
|
|
{ worktree = Just ".." }
|
|
|
|
}
|
|
|
|
_ -> noop
|
|
|
|
|
2017-02-17 19:21:39 +00:00
|
|
|
updateInsteadEmulation :: CommandStart
|
|
|
|
updateInsteadEmulation = do
|
|
|
|
prepMerge
|
2018-10-19 19:17:48 +00:00
|
|
|
mergeLocal mergeConfig def =<< getCurrentBranch
|