mirror of https://github.com/voidlizard/hbs2
fixing git clone
This commit is contained in:
parent
9a2b9d8df7
commit
43b4af607e
|
@ -11,10 +11,15 @@ import Data.Config.Suckless
|
||||||
|
|
||||||
import HBS2Git.Types
|
import HBS2Git.Types
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
|
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
|
||||||
|
import System.Environment
|
||||||
|
import System.IO (stderr)
|
||||||
|
|
||||||
-- type C = MegaParsec
|
-- type C = MegaParsec
|
||||||
|
|
||||||
appName :: FilePath
|
appName :: FilePath
|
||||||
|
@ -47,8 +52,14 @@ configPathOld pwd = liftIO do
|
||||||
|
|
||||||
configPath :: MonadIO m => FilePath -> m FilePath
|
configPath :: MonadIO m => FilePath -> m FilePath
|
||||||
configPath _ = liftIO do
|
configPath _ = liftIO do
|
||||||
here <- liftIO getCurrentDirectory
|
env <- liftIO getEnvironment
|
||||||
(findGitDir here <&> fmap ((</> ".hbs2") . takeDirectory)) `orDie` "*** hbs2-git: .git directory not found"
|
-- hPrint stderr $ pretty env
|
||||||
|
pwd <- liftIO getCurrentDirectory
|
||||||
|
git <- findGitDir pwd
|
||||||
|
byEnv <- lookupEnv "GIT_DIR"
|
||||||
|
path <- pure (git <|> byEnv) `orDie` "*** hbs2-git: .git directory not found"
|
||||||
|
debug $ "AAAAA " <+> pretty path
|
||||||
|
pure (takeDirectory path </> ".hbs2")
|
||||||
|
|
||||||
data ConfigPathInfo = ConfigPathInfo {
|
data ConfigPathInfo = ConfigPathInfo {
|
||||||
configRepoParentDir :: FilePath,
|
configRepoParentDir :: FilePath,
|
||||||
|
@ -61,7 +72,7 @@ getConfigPathInfo :: MonadIO m => m ConfigPathInfo
|
||||||
getConfigPathInfo = do
|
getConfigPathInfo = do
|
||||||
trace "getConfigPathInfo"
|
trace "getConfigPathInfo"
|
||||||
gitDir <- findWorkingGitDir
|
gitDir <- findWorkingGitDir
|
||||||
let pwd = takeDirectory gitDir
|
pwd <- configPath "" <&> takeDirectory
|
||||||
confP <- configPath pwd
|
confP <- configPath pwd
|
||||||
let confFile = confP </> "config"
|
let confFile = confP </> "config"
|
||||||
trace $ "git dir" <+> pretty gitDir
|
trace $ "git dir" <+> pretty gitDir
|
||||||
|
|
|
@ -4,6 +4,7 @@ import HBS2.Prelude.Plated
|
||||||
import HBS2.System.Logger.Simple
|
import HBS2.System.Logger.Simple
|
||||||
import HBS2.OrDie
|
import HBS2.OrDie
|
||||||
|
|
||||||
|
import HBS2Git.Types
|
||||||
import HBS2.Git.Types
|
import HBS2.Git.Types
|
||||||
import HBS2Git.Config
|
import HBS2Git.Config
|
||||||
import HBS2Git.PrettyStuff
|
import HBS2Git.PrettyStuff
|
||||||
|
@ -22,14 +23,20 @@ import UnliftIO
|
||||||
-- например, переносит конфиг
|
-- например, переносит конфиг
|
||||||
|
|
||||||
evolve :: MonadIO m => m ()
|
evolve :: MonadIO m => m ()
|
||||||
evolve = do
|
evolve = void $ runMaybeT do
|
||||||
trace "DO EVOLVE"
|
trace "DO EVOLVE MAZAFAKA!"
|
||||||
|
|
||||||
|
here <- liftIO getCurrentDirectory
|
||||||
|
|
||||||
|
debug $ "evolve: current directory:" <+> pretty here
|
||||||
|
|
||||||
|
cfg <- configPath ""
|
||||||
|
|
||||||
|
debug $ "*** GIT DIRECTORY" <+> pretty cfg
|
||||||
|
|
||||||
migrateConfig
|
migrateConfig
|
||||||
generateCookie
|
generateCookie
|
||||||
|
|
||||||
pure ()
|
|
||||||
|
|
||||||
|
|
||||||
generateCookie :: MonadIO m => m ()
|
generateCookie :: MonadIO m => m ()
|
||||||
generateCookie = void $ runMaybeT do
|
generateCookie = void $ runMaybeT do
|
||||||
|
@ -48,14 +55,12 @@ generateCookie = void $ runMaybeT do
|
||||||
migrateConfig :: MonadIO m => m ()
|
migrateConfig :: MonadIO m => m ()
|
||||||
migrateConfig = void $ runMaybeT do
|
migrateConfig = void $ runMaybeT do
|
||||||
here <- liftIO getCurrentDirectory
|
here <- liftIO getCurrentDirectory
|
||||||
rootDir <- (findGitDir here <&> fmap takeDirectory) `orDie` "*** hbs2-git: working directory not found"
|
|
||||||
|
rootDir <- configPath "" <&> takeDirectory
|
||||||
|
|
||||||
oldPath <- configPathOld here
|
oldPath <- configPathOld here
|
||||||
let oldConf = oldPath </> "config"
|
let oldConf = oldPath </> "config"
|
||||||
|
|
||||||
guard =<< liftIO (doesDirectoryExist oldPath)
|
|
||||||
guard =<< liftIO (doesFileExist oldConf)
|
|
||||||
|
|
||||||
let newConfDir = rootDir </> ".hbs2"
|
let newConfDir = rootDir </> ".hbs2"
|
||||||
let newConfFile = newConfDir </> "config"
|
let newConfFile = newConfDir </> "config"
|
||||||
|
|
||||||
|
@ -70,6 +75,12 @@ migrateConfig = void $ runMaybeT do
|
||||||
liftIO do
|
liftIO do
|
||||||
hPutDoc stderr $ red "evolve: creating new config" <+> pretty newConfFile <> line
|
hPutDoc stderr $ red "evolve: creating new config" <+> pretty newConfFile <> line
|
||||||
createDirectoryIfMissing True newConfDir
|
createDirectoryIfMissing True newConfDir
|
||||||
|
|
||||||
|
appendFile newConfFile ""
|
||||||
|
|
||||||
|
oldHere <- doesFileExist oldConf
|
||||||
|
|
||||||
|
when oldHere do
|
||||||
hPutDoc stderr $ red "evolve: moving config to" <+> pretty newConfFile <> line
|
hPutDoc stderr $ red "evolve: moving config to" <+> pretty newConfFile <> line
|
||||||
liftIO $ renameFile oldConf newConfFile
|
liftIO $ renameFile oldConf newConfFile
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue