Formats repo
This commit is contained in:
@@ -10,13 +10,11 @@ import TestHelper
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "gitCommitAll" $ do
|
||||
|
||||
it "creates a commit after a file is changed" $ do
|
||||
logger <- testLogger
|
||||
withTempGitRepo $ \repo -> do
|
||||
countBefore <- commitCount repo
|
||||
countBefore `shouldBe` 1 -- initial commit from helper
|
||||
|
||||
countBefore `shouldBe` 1 -- initial commit from helper
|
||||
writeFile (repo </> "hello.txt") "hello world"
|
||||
(code, _, _) <- gitCommitAll logger repo
|
||||
code `shouldBe` ExitSuccess
|
||||
@@ -57,7 +55,6 @@ spec = do
|
||||
countAfter2 `shouldBe` countBefore2
|
||||
|
||||
describe "startup sync" $ do
|
||||
|
||||
it "commits and pushes uncommitted changes on startup" $ do
|
||||
logger <- testLogger
|
||||
withTempGitRepoWithRemote $ \repo -> do
|
||||
@@ -67,11 +64,12 @@ spec = do
|
||||
countBefore <- commitCount repo
|
||||
countBefore `shouldBe` 1
|
||||
|
||||
let cfg = defaultRepoConfig {rcPath = repo}
|
||||
let opts = defaultOptions
|
||||
{ optRepos = [cfg]
|
||||
, optNotifyCmd = "true" -- avoid firing notify-send
|
||||
}
|
||||
let cfg = defaultRepoConfig{rcPath = repo}
|
||||
let opts =
|
||||
defaultOptions
|
||||
{ optRepos = [cfg]
|
||||
, optNotifyCmd = "true" -- avoid firing notify-send
|
||||
}
|
||||
syncRepo opts logger cfg
|
||||
|
||||
countAfter <- commitCount repo
|
||||
|
||||
+2
-3
@@ -12,7 +12,6 @@ import TestHelper
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "gitPull" $ do
|
||||
|
||||
it "pulls changes from remote 'origin'" $ do
|
||||
withTempGitRepoWithRemote $ \local -> do
|
||||
-- Make a second commit on local and push to remote
|
||||
@@ -27,7 +26,7 @@ spec = do
|
||||
countBefore <- commitCount local
|
||||
countBefore `shouldBe` 1
|
||||
|
||||
let cfg = defaultRepoConfig {rcPath = local}
|
||||
let cfg = defaultRepoConfig{rcPath = local}
|
||||
(code, _, _) <- gitPull cfg
|
||||
code `shouldBe` ExitSuccess
|
||||
|
||||
@@ -73,7 +72,7 @@ spec = do
|
||||
|
||||
-- Pull with --rebase: local commits are rebased on top
|
||||
-- of the fetched remote commit, yielding a linear history.
|
||||
let cfg = defaultRepoConfig {rcPath = localDir}
|
||||
let cfg = defaultRepoConfig{rcPath = localDir}
|
||||
(code, _, _) <- gitPull cfg
|
||||
code `shouldBe` ExitSuccess
|
||||
-- Rebase produces linear history: 3 commits, no merge commit
|
||||
|
||||
@@ -7,7 +7,6 @@ import TestHelper
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "isInMiddleOfOperation" $ do
|
||||
|
||||
it "returns False when no operation is in progress" $ do
|
||||
withTempGitRepo $ \repo -> do
|
||||
result <- isInMiddleOfOperation repo
|
||||
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
module Main (main) where
|
||||
|
||||
import Test.Hspec
|
||||
import qualified GitCommitSpec
|
||||
import qualified GitPullSpec
|
||||
import qualified GitSafetySpec
|
||||
import Test.Hspec
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
|
||||
+7
-5
@@ -41,8 +41,9 @@ rawGit args = do
|
||||
testLogger :: IO Logger
|
||||
testLogger = Logger <$> newMVar ()
|
||||
|
||||
-- | Create a temporary git repository, configure a user, make an initial
|
||||
-- commit on branch "main", run the action with the repo path, then clean up.
|
||||
{- | Create a temporary git repository, configure a user, make an initial
|
||||
commit on branch "main", run the action with the repo path, then clean up.
|
||||
-}
|
||||
withTempGitRepo :: (FilePath -> IO a) -> IO a
|
||||
withTempGitRepo action = withSystemTempDirectory "converge-test" $ \tmp -> do
|
||||
let repo = tmp </> "repo"
|
||||
@@ -56,9 +57,10 @@ withTempGitRepo action = withSystemTempDirectory "converge-test" $ \tmp -> do
|
||||
_ <- runGitIn repo ["commit", "-m", "initial commit"]
|
||||
action repo
|
||||
|
||||
-- | Create a temporary git repo with a bare remote, run the action with the
|
||||
-- local repo path, then clean up. The local repo is pushed to the remote
|
||||
-- so origin/main is reachable via fetch/pull.
|
||||
{- | Create a temporary git repo with a bare remote, run the action with the
|
||||
local repo path, then clean up. The local repo is pushed to the remote
|
||||
so origin/main is reachable via fetch/pull.
|
||||
-}
|
||||
withTempGitRepoWithRemote :: (FilePath -> IO a) -> IO a
|
||||
withTempGitRepoWithRemote action = withSystemTempDirectory "converge-test-remote" $ \tmp -> do
|
||||
let remoteDir = tmp </> "remote.git"
|
||||
|
||||
Reference in New Issue
Block a user