[#501] Using git commandline

Resolves #501
This commit is contained in:
Runar Bjarnason 2019-06-06 16:15:21 -04:00
parent 40261f2047
commit f1d44a6dfc
4 changed files with 67 additions and 10 deletions

View 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

View File

@ -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

View File

@ -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,

View File

@ -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