Created
September 19, 2013 23:10
-
-
Save dysinger/6631123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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