setupUpstreamMaster :: String -> IO ()
setupUpstreamMaster newref = do
        changeWorkingDirectory =<< dotPropellor
        go =<< catchMaybeIO getoldrev
  where
        go Nothing = warnoutofdate False
        go (Just oldref) = do
                let tmprepo = ".git/propellordisttmp"
                let cleantmprepo = void $ catchMaybeIO $ 
removeDirectoryRecursive tmprepo
                cleantmprepo
                git ["clone", "--quiet", ".", tmprepo]

                changeWorkingDirectory tmprepo
                git ["fetch", distrepo, "--quiet"]
                git ["reset", "--hard", oldref, "--quiet"]
                v <- gitVersion
                let mergeparams =
                        [ "merge", newref
                        , "-s", "recursive"
                        , "-Xtheirs"
                        , "--quiet"
                        , "-m", "merging upstream version"
                        ] ++ if v >= [2,9]
                                then [ "--allow-unrelated-histories" ]
                                else []
                git mergeparams

                void $ fetchUpstreamBranch tmprepo
                cleantmprepo
                warnoutofdate True

        getoldrev = takeWhile (/= '\n')
                <$> readProcess "git" ["show-ref", upstreambranch, "--hash"]

        git = run "git"
        run cmd ps = unlessM (boolSystem cmd (map Param ps)) $
                error $ "Failed to run " ++ cmd ++ " " ++ show ps

Yes here

Reply via email to