2014-11-12 19:41:15 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-11-12 19:41:15 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Proxy where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
|
|
|
import Config
|
|
|
|
import Utility.Tmp
|
|
|
|
import Utility.Env
|
|
|
|
import Annex.Direct
|
|
|
|
import qualified Git.Branch
|
|
|
|
import qualified Git.Sha
|
|
|
|
|
|
|
|
cmd :: [Command]
|
|
|
|
cmd = [notBareRepo $
|
|
|
|
command "proxy" ("-- git command") seek
|
2014-11-13 17:59:00 +00:00
|
|
|
SectionPlumbing "safely bypass direct mode guard"]
|
2014-11-12 19:41:15 +00:00
|
|
|
|
|
|
|
seek :: CommandSeek
|
2014-11-13 17:56:29 +00:00
|
|
|
seek = withWords start
|
2014-11-12 19:41:15 +00:00
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start [] = error "Did not specify command to run."
|
|
|
|
start (c:ps) = liftIO . exitWith =<< ifM isDirect
|
|
|
|
( do
|
|
|
|
g <- gitRepo
|
|
|
|
withTmpDirIn (gitAnnexTmpMiscDir g) "proxy" go
|
|
|
|
, liftIO $ safeSystem c (map Param ps)
|
|
|
|
)
|
|
|
|
where
|
|
|
|
go tmp = do
|
|
|
|
oldref <- fromMaybe Git.Sha.emptyTree
|
|
|
|
<$> inRepo Git.Branch.currentSha
|
|
|
|
exitcode <- liftIO $ proxy tmp
|
|
|
|
mergeDirectCleanup tmp oldref
|
|
|
|
return exitcode
|
|
|
|
proxy tmp = do
|
|
|
|
usetmp <- Just . addEntry "GIT_WORK_TREE" tmp <$> getEnvironment
|
|
|
|
unlessM (boolSystemEnv "git" [Param "checkout", Param "--", Param "."] usetmp) $
|
|
|
|
error "Failed to set up proxy work tree."
|
|
|
|
safeSystemEnv c (map Param ps) usetmp
|