diff --git a/src/Converge.hs b/src/Converge.hs index 4cc9e54..a962a4f 100644 --- a/src/Converge.hs +++ b/src/Converge.hs @@ -272,7 +272,8 @@ syncRepo opts logger repo = do logRepo logger repo "nothing to commit (working tree clean)" | otherwise -> do logRepo logger repo ("commit FAILED (exit " <> T.pack (show commitCode) <> "): " <> T.strip (commitOut <> commitErr)) - notifyUser opts + notifyUser + opts "Converge: Commit Failed" ("Commit failed in " <> rcPath repo <> " (exit " <> show commitCode <> ")") -- Pull @@ -286,7 +287,8 @@ syncRepo opts logger repo = do else logRepo logger repo ("pull succeeded:\n" <> trimmed) _ -> do logRepo logger repo ("pull FAILED (exit " <> T.pack (show pullCode) <> "): " <> T.strip (pullOut <> pullErr)) - notifyUser opts + notifyUser + opts "Converge: Pull Failed" ("Pull failed in " <> rcPath repo <> " (exit " <> show pullCode <> ")") -- Conflict check @@ -294,7 +296,8 @@ syncRepo opts logger repo = do if conflicted then do logRepo logger repo "*** MERGE CONFLICT detected! ***" - notifyUser opts + notifyUser + opts "Converge: Merge Conflict" ("A merge conflict occurred in " <> rcPath repo <> ". Manual resolution required.") else do @@ -306,7 +309,8 @@ syncRepo opts logger repo = do logRepo logger repo "push succeeded" _ -> do logRepo logger repo ("push FAILED (exit " <> T.pack (show pushCode) <> "): " <> T.strip (pushOut <> pushErr)) - notifyUser opts + notifyUser + opts "Converge: Push Failed" ("Push failed in " <> rcPath repo <> " (exit " <> show pushCode <> ")") diff --git a/test/GitCommitSpec.hs b/test/GitCommitSpec.hs index 1c64646..57cbea1 100644 --- a/test/GitCommitSpec.hs +++ b/test/GitCommitSpec.hs @@ -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 diff --git a/test/GitPullSpec.hs b/test/GitPullSpec.hs index 1980b5e..33fe262 100644 --- a/test/GitPullSpec.hs +++ b/test/GitPullSpec.hs @@ -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 diff --git a/test/GitSafetySpec.hs b/test/GitSafetySpec.hs index fe61fe5..0107900 100644 --- a/test/GitSafetySpec.hs +++ b/test/GitSafetySpec.hs @@ -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 diff --git a/test/Spec.hs b/test/Spec.hs index fb06a05..cc12fee 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -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 diff --git a/test/TestHelper.hs b/test/TestHelper.hs index 01d7809..59a06c7 100644 --- a/test/TestHelper.hs +++ b/test/TestHelper.hs @@ -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"