Skip to content

Instantly share code, notes, and snippets.

@cartazio
Forked from dysinger/Git.hs
Created September 19, 2013 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartazio/6631253 to your computer and use it in GitHub Desktop.
Save cartazio/6631253 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Git where
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import Prelude hiding (FilePath)
import Shelly
git :: [Text] -> Sh Text
git = run "git"
git_ :: [Text] -> Sh ()
git_ = run_ "git"
gitCommit_ :: [Text] -> Sh ()
gitCommit_ = git_ . (:) "commit"
gitInit_ :: [Text] -> Sh ()
gitInit_ = git_ . (:) "init"
gitAdd_ :: [Text] -> Sh ()
gitAdd_ = git_ . (:) "add"
gitMerge_ :: [Text] -> Sh ()
gitMerge_ = git_ . (:) "merge"
gitMergeSubtree_ :: Text -> Text -> Text -> Sh ()
gitMergeSubtree_ otherGitUrl otherRemote otherBranch = do
let otherBranch' = toTextIgnore $ otherRemote </> otherBranch
gitRemoteAdd_ ["-f", otherRemote, otherGitUrl]
gitMerge_ ["-s", "ours", "--no-commit", otherBranch' ]
gitReadTree_ [T.concat ["--prefix=", otherRemote, "/"], "-u", otherBranch']
gitCommit_ ["-m", T.concat ["Merging subtree ", otherRemote]]
gitPullAsSubtree_ :: Text -> Text -> Sh ()
gitPullAsSubtree_ otherRemote otherBranch =
gitPull_ ["-s", "subtree", otherRemote, otherBranch]
gitPull_ :: [Text] -> Sh ()
gitPull_ = git_ . (:) "pull"
gitReadTree_ :: [Text] -> Sh ()
gitReadTree_ = git_ . (:) "read-tree"
gitRemote_ :: [Text] -> Sh ()
gitRemote_ = git_ . (:) "remote"
gitRemoteAdd_ :: [Text] -> Sh ()
gitRemoteAdd_ = gitRemote_ . (:) "add"
gitRemoteUpdate_ :: [Text] -> Sh ()
gitRemoteUpdate_ = gitRemote_ . (:) "update"
gitRevList :: [Text] -> Sh Text
gitRevList = git . (:) "rev-list"
gitRevListHeadCount :: Sh Int
gitRevListHeadCount =
return . read . T.unpack =<< gitRevList [ "HEAD", "--count" ]
gitFilterBranch :: Sh ()
gitFilterBranch = undefined
-- TODO show some common examples of rewriting history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment