Formats repo
This commit is contained in:
+8
-4
@@ -272,7 +272,8 @@ syncRepo opts logger repo = do
|
|||||||
logRepo logger repo "nothing to commit (working tree clean)"
|
logRepo logger repo "nothing to commit (working tree clean)"
|
||||||
| otherwise -> do
|
| otherwise -> do
|
||||||
logRepo logger repo ("commit FAILED (exit " <> T.pack (show commitCode) <> "): " <> T.strip (commitOut <> commitErr))
|
logRepo logger repo ("commit FAILED (exit " <> T.pack (show commitCode) <> "): " <> T.strip (commitOut <> commitErr))
|
||||||
notifyUser opts
|
notifyUser
|
||||||
|
opts
|
||||||
"Converge: Commit Failed"
|
"Converge: Commit Failed"
|
||||||
("Commit failed in " <> rcPath repo <> " (exit " <> show commitCode <> ")")
|
("Commit failed in " <> rcPath repo <> " (exit " <> show commitCode <> ")")
|
||||||
-- Pull
|
-- Pull
|
||||||
@@ -286,7 +287,8 @@ syncRepo opts logger repo = do
|
|||||||
else logRepo logger repo ("pull succeeded:\n" <> trimmed)
|
else logRepo logger repo ("pull succeeded:\n" <> trimmed)
|
||||||
_ -> do
|
_ -> do
|
||||||
logRepo logger repo ("pull FAILED (exit " <> T.pack (show pullCode) <> "): " <> T.strip (pullOut <> pullErr))
|
logRepo logger repo ("pull FAILED (exit " <> T.pack (show pullCode) <> "): " <> T.strip (pullOut <> pullErr))
|
||||||
notifyUser opts
|
notifyUser
|
||||||
|
opts
|
||||||
"Converge: Pull Failed"
|
"Converge: Pull Failed"
|
||||||
("Pull failed in " <> rcPath repo <> " (exit " <> show pullCode <> ")")
|
("Pull failed in " <> rcPath repo <> " (exit " <> show pullCode <> ")")
|
||||||
-- Conflict check
|
-- Conflict check
|
||||||
@@ -294,7 +296,8 @@ syncRepo opts logger repo = do
|
|||||||
if conflicted
|
if conflicted
|
||||||
then do
|
then do
|
||||||
logRepo logger repo "*** MERGE CONFLICT detected! ***"
|
logRepo logger repo "*** MERGE CONFLICT detected! ***"
|
||||||
notifyUser opts
|
notifyUser
|
||||||
|
opts
|
||||||
"Converge: Merge Conflict"
|
"Converge: Merge Conflict"
|
||||||
("A merge conflict occurred in " <> rcPath repo <> ". Manual resolution required.")
|
("A merge conflict occurred in " <> rcPath repo <> ". Manual resolution required.")
|
||||||
else do
|
else do
|
||||||
@@ -306,7 +309,8 @@ syncRepo opts logger repo = do
|
|||||||
logRepo logger repo "push succeeded"
|
logRepo logger repo "push succeeded"
|
||||||
_ -> do
|
_ -> do
|
||||||
logRepo logger repo ("push FAILED (exit " <> T.pack (show pushCode) <> "): " <> T.strip (pushOut <> pushErr))
|
logRepo logger repo ("push FAILED (exit " <> T.pack (show pushCode) <> "): " <> T.strip (pushOut <> pushErr))
|
||||||
notifyUser opts
|
notifyUser
|
||||||
|
opts
|
||||||
"Converge: Push Failed"
|
"Converge: Push Failed"
|
||||||
("Push failed in " <> rcPath repo <> " (exit " <> show pushCode <> ")")
|
("Push failed in " <> rcPath repo <> " (exit " <> show pushCode <> ")")
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,11 @@ import TestHelper
|
|||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "gitCommitAll" $ do
|
describe "gitCommitAll" $ do
|
||||||
|
|
||||||
it "creates a commit after a file is changed" $ do
|
it "creates a commit after a file is changed" $ do
|
||||||
logger <- testLogger
|
logger <- testLogger
|
||||||
withTempGitRepo $ \repo -> do
|
withTempGitRepo $ \repo -> do
|
||||||
countBefore <- commitCount repo
|
countBefore <- commitCount repo
|
||||||
countBefore `shouldBe` 1 -- initial commit from helper
|
countBefore `shouldBe` 1 -- initial commit from helper
|
||||||
|
|
||||||
writeFile (repo </> "hello.txt") "hello world"
|
writeFile (repo </> "hello.txt") "hello world"
|
||||||
(code, _, _) <- gitCommitAll logger repo
|
(code, _, _) <- gitCommitAll logger repo
|
||||||
code `shouldBe` ExitSuccess
|
code `shouldBe` ExitSuccess
|
||||||
@@ -57,7 +55,6 @@ spec = do
|
|||||||
countAfter2 `shouldBe` countBefore2
|
countAfter2 `shouldBe` countBefore2
|
||||||
|
|
||||||
describe "startup sync" $ do
|
describe "startup sync" $ do
|
||||||
|
|
||||||
it "commits and pushes uncommitted changes on startup" $ do
|
it "commits and pushes uncommitted changes on startup" $ do
|
||||||
logger <- testLogger
|
logger <- testLogger
|
||||||
withTempGitRepoWithRemote $ \repo -> do
|
withTempGitRepoWithRemote $ \repo -> do
|
||||||
@@ -67,11 +64,12 @@ spec = do
|
|||||||
countBefore <- commitCount repo
|
countBefore <- commitCount repo
|
||||||
countBefore `shouldBe` 1
|
countBefore `shouldBe` 1
|
||||||
|
|
||||||
let cfg = defaultRepoConfig {rcPath = repo}
|
let cfg = defaultRepoConfig{rcPath = repo}
|
||||||
let opts = defaultOptions
|
let opts =
|
||||||
{ optRepos = [cfg]
|
defaultOptions
|
||||||
, optNotifyCmd = "true" -- avoid firing notify-send
|
{ optRepos = [cfg]
|
||||||
}
|
, optNotifyCmd = "true" -- avoid firing notify-send
|
||||||
|
}
|
||||||
syncRepo opts logger cfg
|
syncRepo opts logger cfg
|
||||||
|
|
||||||
countAfter <- commitCount repo
|
countAfter <- commitCount repo
|
||||||
|
|||||||
+2
-3
@@ -12,7 +12,6 @@ import TestHelper
|
|||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "gitPull" $ do
|
describe "gitPull" $ do
|
||||||
|
|
||||||
it "pulls changes from remote 'origin'" $ do
|
it "pulls changes from remote 'origin'" $ do
|
||||||
withTempGitRepoWithRemote $ \local -> do
|
withTempGitRepoWithRemote $ \local -> do
|
||||||
-- Make a second commit on local and push to remote
|
-- Make a second commit on local and push to remote
|
||||||
@@ -27,7 +26,7 @@ spec = do
|
|||||||
countBefore <- commitCount local
|
countBefore <- commitCount local
|
||||||
countBefore `shouldBe` 1
|
countBefore `shouldBe` 1
|
||||||
|
|
||||||
let cfg = defaultRepoConfig {rcPath = local}
|
let cfg = defaultRepoConfig{rcPath = local}
|
||||||
(code, _, _) <- gitPull cfg
|
(code, _, _) <- gitPull cfg
|
||||||
code `shouldBe` ExitSuccess
|
code `shouldBe` ExitSuccess
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ spec = do
|
|||||||
|
|
||||||
-- Pull with --rebase: local commits are rebased on top
|
-- Pull with --rebase: local commits are rebased on top
|
||||||
-- of the fetched remote commit, yielding a linear history.
|
-- of the fetched remote commit, yielding a linear history.
|
||||||
let cfg = defaultRepoConfig {rcPath = localDir}
|
let cfg = defaultRepoConfig{rcPath = localDir}
|
||||||
(code, _, _) <- gitPull cfg
|
(code, _, _) <- gitPull cfg
|
||||||
code `shouldBe` ExitSuccess
|
code `shouldBe` ExitSuccess
|
||||||
-- Rebase produces linear history: 3 commits, no merge commit
|
-- Rebase produces linear history: 3 commits, no merge commit
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import TestHelper
|
|||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "isInMiddleOfOperation" $ do
|
describe "isInMiddleOfOperation" $ do
|
||||||
|
|
||||||
it "returns False when no operation is in progress" $ do
|
it "returns False when no operation is in progress" $ do
|
||||||
withTempGitRepo $ \repo -> do
|
withTempGitRepo $ \repo -> do
|
||||||
result <- isInMiddleOfOperation repo
|
result <- isInMiddleOfOperation repo
|
||||||
|
|||||||
+1
-1
@@ -1,9 +1,9 @@
|
|||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import Test.Hspec
|
|
||||||
import qualified GitCommitSpec
|
import qualified GitCommitSpec
|
||||||
import qualified GitPullSpec
|
import qualified GitPullSpec
|
||||||
import qualified GitSafetySpec
|
import qualified GitSafetySpec
|
||||||
|
import Test.Hspec
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = hspec $ do
|
main = hspec $ do
|
||||||
|
|||||||
+7
-5
@@ -41,8 +41,9 @@ rawGit args = do
|
|||||||
testLogger :: IO Logger
|
testLogger :: IO Logger
|
||||||
testLogger = Logger <$> newMVar ()
|
testLogger = Logger <$> newMVar ()
|
||||||
|
|
||||||
-- | Create a temporary git repository, configure a user, make an initial
|
{- | 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.
|
commit on branch "main", run the action with the repo path, then clean up.
|
||||||
|
-}
|
||||||
withTempGitRepo :: (FilePath -> IO a) -> IO a
|
withTempGitRepo :: (FilePath -> IO a) -> IO a
|
||||||
withTempGitRepo action = withSystemTempDirectory "converge-test" $ \tmp -> do
|
withTempGitRepo action = withSystemTempDirectory "converge-test" $ \tmp -> do
|
||||||
let repo = tmp </> "repo"
|
let repo = tmp </> "repo"
|
||||||
@@ -56,9 +57,10 @@ withTempGitRepo action = withSystemTempDirectory "converge-test" $ \tmp -> do
|
|||||||
_ <- runGitIn repo ["commit", "-m", "initial commit"]
|
_ <- runGitIn repo ["commit", "-m", "initial commit"]
|
||||||
action repo
|
action repo
|
||||||
|
|
||||||
-- | Create a temporary git repo with a bare remote, run the action with the
|
{- | 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
|
local repo path, then clean up. The local repo is pushed to the remote
|
||||||
-- so origin/main is reachable via fetch/pull.
|
so origin/main is reachable via fetch/pull.
|
||||||
|
-}
|
||||||
withTempGitRepoWithRemote :: (FilePath -> IO a) -> IO a
|
withTempGitRepoWithRemote :: (FilePath -> IO a) -> IO a
|
||||||
withTempGitRepoWithRemote action = withSystemTempDirectory "converge-test-remote" $ \tmp -> do
|
withTempGitRepoWithRemote action = withSystemTempDirectory "converge-test-remote" $ \tmp -> do
|
||||||
let remoteDir = tmp </> "remote.git"
|
let remoteDir = tmp </> "remote.git"
|
||||||
|
|||||||
Reference in New Issue
Block a user