Formats repo

This commit is contained in:
2026-05-13 22:15:55 -04:00
parent 63e034fd01
commit e0f986a5ee
6 changed files with 25 additions and 23 deletions
+8 -4
View File
@@ -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 <> ")")
+3 -5
View File
@@ -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
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,8 +64,9 @@ spec = do
countBefore <- commitCount repo
countBefore `shouldBe` 1
let cfg = defaultRepoConfig {rcPath = repo}
let opts = defaultOptions
let cfg = defaultRepoConfig{rcPath = repo}
let opts =
defaultOptions
{ optRepos = [cfg]
, optNotifyCmd = "true" -- avoid firing notify-send
}
+2 -3
View File
@@ -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
-1
View File
@@ -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
View File
@@ -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
View File
@@ -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"