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
This commit is contained in:
+1
-1
@@ -305,7 +305,7 @@ gitPull :: RepoConfig -> IO (ExitCode, Text, Text)
|
|||||||
gitPull repo =
|
gitPull repo =
|
||||||
runGitIn
|
runGitIn
|
||||||
(rcPath repo)
|
(rcPath repo)
|
||||||
["pull", "--no-edit", T.unpack (rcRemote repo), T.unpack (rcBranch repo)]
|
["pull", "--rebase", T.unpack (rcRemote repo), T.unpack (rcBranch repo)]
|
||||||
|
|
||||||
-- | Check if the repository currently has merge conflicts.
|
-- | Check if the repository currently has merge conflicts.
|
||||||
hasConflicts :: FilePath -> IO Bool
|
hasConflicts :: FilePath -> IO Bool
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
module GitCommitSpec (spec) where
|
module GitCommitSpec (spec) where
|
||||||
|
|
||||||
import Converge (gitCommitAll)
|
import Converge (gitCommitAll)
|
||||||
import Data.Text (Text)
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import System.Exit (ExitCode (..))
|
import System.Exit (ExitCode (..))
|
||||||
import System.FilePath ((</>))
|
import System.FilePath ((</>))
|
||||||
import System.IO (writeFile)
|
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
import TestHelper
|
import TestHelper
|
||||||
|
|
||||||
|
|||||||
+11
-10
@@ -5,7 +5,6 @@ import qualified Data.Text as T
|
|||||||
import System.Directory (createDirectory)
|
import System.Directory (createDirectory)
|
||||||
import System.Exit (ExitCode (..))
|
import System.Exit (ExitCode (..))
|
||||||
import System.FilePath ((</>))
|
import System.FilePath ((</>))
|
||||||
import System.IO (writeFile)
|
|
||||||
import System.IO.Temp (withSystemTempDirectory)
|
import System.IO.Temp (withSystemTempDirectory)
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
import TestHelper
|
import TestHelper
|
||||||
@@ -72,13 +71,15 @@ spec = do
|
|||||||
_ <- runGitIn otherDir ["commit", "-m", "remote commit"]
|
_ <- runGitIn otherDir ["commit", "-m", "remote commit"]
|
||||||
_ <- runGitIn otherDir ["push", "origin", "main"]
|
_ <- runGitIn otherDir ["push", "origin", "main"]
|
||||||
|
|
||||||
-- Pull into local with divergent history.
|
-- Pull with --rebase: local commits are rebased on top
|
||||||
-- CURRENT BEHAVIOR: git pull --no-edit fails on divergent
|
-- of the fetched remote commit, yielding a linear history.
|
||||||
-- branches (exit 128). The spec requires rebase instead.
|
|
||||||
-- When --rebase is implemented, expect ExitSuccess and
|
|
||||||
-- linear history (commit count = 3).
|
|
||||||
let cfg = defaultRepoConfig {rcPath = localDir}
|
let cfg = defaultRepoConfig {rcPath = localDir}
|
||||||
(code, _, err) <- gitPull cfg
|
(code, _, _) <- gitPull cfg
|
||||||
-- Document current gap: divergent pull fails
|
code `shouldBe` ExitSuccess
|
||||||
code `shouldSatisfy` (/= ExitSuccess)
|
-- Rebase produces linear history: 3 commits, no merge commit
|
||||||
err `shouldSatisfy` ("fast-forward" `T.isInfixOf`)
|
c <- commitCount localDir
|
||||||
|
c `shouldBe` 3
|
||||||
|
-- Verify no merge commits exist (each commit has exactly 1 parent)
|
||||||
|
(_, logOut, _) <- runGitIn localDir ["log", "--format=%P", "--all"]
|
||||||
|
let parentCounts = map (length . words) (lines (T.unpack logOut))
|
||||||
|
parentCounts `shouldSatisfy` all (<= 1)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import qualified Data.Text as T
|
|||||||
import System.Directory (createDirectory)
|
import System.Directory (createDirectory)
|
||||||
import System.Exit (ExitCode)
|
import System.Exit (ExitCode)
|
||||||
import System.FilePath ((</>))
|
import System.FilePath ((</>))
|
||||||
import System.IO (writeFile)
|
|
||||||
import System.IO.Temp (withSystemTempDirectory)
|
import System.IO.Temp (withSystemTempDirectory)
|
||||||
import System.Process (readProcessWithExitCode)
|
import System.Process (readProcessWithExitCode)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user