mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-12 04:34:38 +03:00
parent
40261f2047
commit
f1d44a6dfc
64
parser-typechecker/src/Unison/Codebase/Editor/Git.hs
Normal file
64
parser-typechecker/src/Unison/Codebase/Editor/Git.hs
Normal file
@ -0,0 +1,64 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Unison.Codebase.Editor.Git where
|
||||
|
||||
import Control.Monad ( when )
|
||||
import Control.Monad.Except ( MonadError )
|
||||
import Control.Monad.IO.Class ( MonadIO
|
||||
, liftIO
|
||||
)
|
||||
import Data.Text ( Text )
|
||||
import Shellmet ( )
|
||||
import System.Directory ( getCurrentDirectory
|
||||
, setCurrentDirectory
|
||||
, doesDirectoryExist
|
||||
)
|
||||
import System.FilePath ( (</>) )
|
||||
import Unison.Codebase.FileCodebase2 ( CodebasePath
|
||||
, getRootBranch
|
||||
, putRootBranch
|
||||
, Err
|
||||
)
|
||||
import Unison.Codebase.Branch2 ( Branch )
|
||||
|
||||
-- may need to be different for private repo?
|
||||
-- TODO: handle errors properly
|
||||
pullGithubRootBranch
|
||||
:: MonadIO m
|
||||
=> MonadError Err m => CodebasePath -> Text -> Text -> Text -> m (Branch m)
|
||||
pullGithubRootBranch localPath user repo treeish = do
|
||||
liftIO $ do
|
||||
wd <- getCurrentDirectory
|
||||
setCurrentDirectory localPath
|
||||
exists <- doesDirectoryExist $ localPath </> ".git"
|
||||
let uri = githubUri user repo
|
||||
when (not exists) $ shallowClone uri
|
||||
shallowPull uri treeish
|
||||
setCurrentDirectory wd
|
||||
getRootBranch localPath
|
||||
|
||||
githubUri :: Text -> Text -> Text
|
||||
githubUri user repo = "git@github.com:" <> user <> "/" <> repo <> ".git"
|
||||
|
||||
shallowClone :: Text -> IO ()
|
||||
shallowClone uri = "git" ["clone", "--depth=1", uri]
|
||||
|
||||
shallowPull :: Text -> Text -> IO ()
|
||||
shallowPull uri treeish = do
|
||||
"git" ["fetch", "--depth=1", uri, treeish]
|
||||
"git" ["checkout", treeish]
|
||||
|
||||
pushGithubRootBranch
|
||||
:: MonadError Err m
|
||||
=> MonadIO m => CodebasePath -> Text -> Text -> Text -> Branch m -> m ()
|
||||
pushGithubRootBranch localPath user repo ghbranch b = do
|
||||
putRootBranch localPath b
|
||||
liftIO $ do
|
||||
-- Write the branch to the local path
|
||||
wd <- getCurrentDirectory
|
||||
setCurrentDirectory localPath
|
||||
-- Commit our changes
|
||||
"git" ["commit", "-m", "Sync Unison Codebase"]
|
||||
-- Push our changes to the repo
|
||||
"git" ["push", "--all", githubUri user repo, ghbranch]
|
||||
setCurrentDirectory wd
|
@ -27,8 +27,6 @@ import Data.Text ( Text
|
||||
import Unison.Codebase2 ( Codebase )
|
||||
import qualified Unison.Codebase.Classes as CC
|
||||
import qualified Unison.Codebase2 as Codebase
|
||||
import Unison.Codebase.Branch2 ( Branch
|
||||
)
|
||||
import qualified Unison.Codebase.SearchResult as SR
|
||||
import qualified Unison.Names as OldNames
|
||||
import Unison.Parser ( Ann )
|
||||
@ -69,14 +67,6 @@ data SearchMode = FuzzySearch | ExactSearch
|
||||
--
|
||||
-- Propagate :: Edits -> Branch -> Command m i v (Branch m)
|
||||
|
||||
|
||||
-- may need to be different for private repo?
|
||||
loadGithubRootBranch :: Text -> Text -> Text -> m (Branch m)
|
||||
loadGithubRootBranch _user _repo _treeish = error "todo: loadGithubRootBranch"
|
||||
|
||||
syncGithubRootBranch :: Text -> Text -> Text -> Branch m -> m ()
|
||||
syncGithubRootBranch _user _repo _ghbranch _b = error "todo: syncGithubRootBranch"
|
||||
|
||||
-- data Outcome
|
||||
-- -- New definition that was added to the branch
|
||||
-- = Added
|
||||
|
@ -52,6 +52,7 @@ library
|
||||
Unison.Codebase.Editor
|
||||
Unison.Codebase.Editor.Actions
|
||||
Unison.Codebase.Editor.Command
|
||||
Unison.Codebase.Editor.Git
|
||||
Unison.Codebase.Editor.HandleInput
|
||||
Unison.Codebase.Editor.HandleCommand
|
||||
Unison.Codebase.Editor.Input
|
||||
@ -196,6 +197,7 @@ library
|
||||
regex-base,
|
||||
regex-tdfa,
|
||||
safe,
|
||||
shellmet,
|
||||
split,
|
||||
stm,
|
||||
strings,
|
||||
|
@ -17,6 +17,7 @@ extra-deps:
|
||||
- strings-1.1
|
||||
- relation-0.2.1
|
||||
- guid-0.1.0
|
||||
- shellmet-0.0.1
|
||||
|
||||
ghc-options:
|
||||
# All packages
|
||||
|
Loading…
Reference in New Issue
Block a user