Files
converge/test/GitCommitSpec.hs
T
jbrechtel 4bc23b5d7c Use --rebase instead of --no-edit in gitPull
git pull --no-edit fails with exit 128 on divergent branches because
fast-forward is impossible.  Using --rebase handles divergent histories
by rebasing local commits on top of fetched remote commits, producing
a linear history without merge commits.

- src/Converge.hs: Change gitPull from --no-edit to --rebase
- test/GitPullSpec.hs: Update rebase test to expect success and
  verify linear history (3 commits, no merge parents)
- test/*.hs: Clean up unused imports
2026-05-13 21:48:49 -04:00

58 lines
2.3 KiB
Haskell

module GitCommitSpec (spec) where
import Converge (gitCommitAll)
import qualified Data.Text as T
import System.Exit (ExitCode (..))
import System.FilePath ((</>))
import Test.Hspec
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
countAfter <- commitCount repo
countAfter `shouldBe` (countBefore + 1)
it "includes the changed file in the commit" $ do
logger <- testLogger
withTempGitRepo $ \repo -> do
writeFile (repo </> "data.txt") "some data"
(code, _, _) <- gitCommitAll logger repo
code `shouldBe` ExitSuccess
(_, logOut, _) <- runGitIn repo ["log", "-1", "--name-only", "--oneline"]
logOut `shouldSatisfy` ("data.txt" `T.isInfixOf`)
it "does not create a new commit when there are no changes" $ do
logger <- testLogger
withTempGitRepo $ \repo -> do
countBefore <- commitCount repo
(code, _, _) <- gitCommitAll logger repo
-- git commit exits non-zero when there is nothing to commit
code `shouldSatisfy` (/= ExitSuccess)
countAfter <- commitCount repo
countAfter `shouldBe` countBefore
it "creates only one commit when called multiple times with the same staged changes" $ do
logger <- testLogger
withTempGitRepo $ \repo -> do
writeFile (repo </> "single.txt") "single change"
(code1, _, _) <- gitCommitAll logger repo
code1 `shouldBe` ExitSuccess
-- Second call: nothing left to commit
countBefore2 <- commitCount repo
(code2, _, _) <- gitCommitAll logger repo
code2 `shouldSatisfy` (/= ExitSuccess)
countAfter2 <- commitCount repo
countAfter2 `shouldBe` countBefore2