module Restyler.Git
    (
    -- * Class of actions that require the Clone
      HasGit(..)

    -- * Functions needed to establish a Clone
    -- | Therefore, they only require @'HasProcess'@
    , gitClone
    , gitFetch
    , gitCheckout
    , gitCheckoutExisting
    )
where

import Restyler.Prelude

import Restyler.App.Class

class HasGit env where
    gitPush :: String -> RIO env ()
    gitPushForce :: String -> RIO env ()
    gitMergeBase :: String -> RIO env (Maybe String)
    gitDiffNameOnly :: Maybe String -> RIO env [FilePath]
    gitCommitAll :: String -> RIO env String
    gitMerge :: String -> RIO env ()

gitClone :: HasProcess env => String -> FilePath -> RIO env ()
gitClone :: String -> String -> RIO env ()
gitClone url :: String
url dir :: String
dir = String -> [String] -> RIO env ()
forall env. HasProcess env => String -> [String] -> RIO env ()
callProcess "git" ["clone", "--quiet", String
url, String
dir]

gitFetch :: HasProcess env => String -> String -> RIO env ()
gitFetch :: String -> String -> RIO env ()
gitFetch remoteRef :: String
remoteRef localRef :: String
localRef =
    String -> [String] -> RIO env ()
forall env. HasProcess env => String -> [String] -> RIO env ()
callProcess "git" ["fetch", "origin", String
remoteRef String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ":" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
localRef]

gitCheckout :: HasProcess env => String -> RIO env ()
gitCheckout :: String -> RIO env ()
gitCheckout branch :: String
branch =
    String -> [String] -> RIO env ()
forall env. HasProcess env => String -> [String] -> RIO env ()
callProcess "git" ["checkout", "--no-progress", "-b", String
branch]

gitCheckoutExisting :: HasProcess env => String -> RIO env ()
gitCheckoutExisting :: String -> RIO env ()
gitCheckoutExisting branch :: String
branch =
    String -> [String] -> RIO env ()
forall env. HasProcess env => String -> [String] -> RIO env ()
callProcess "git" ["checkout", "--no-progress", String
branch]