module Unison.Codebase.Editor.HandleInput.CommitMerge
( handleCommitMerge,
)
where
import U.Codebase.Sqlite.Project qualified
import U.Codebase.Sqlite.ProjectBranch (ProjectBranch (..))
import U.Codebase.Sqlite.Queries qualified as Queries
import Unison.Cli.Monad (Cli)
import Unison.Cli.Monad qualified as Cli
import Unison.Cli.MonadUtils qualified as Cli
import Unison.Cli.ProjectUtils qualified as ProjectUtils
import Unison.Codebase.Editor.HandleInput.DeleteBranch qualified as DeleteBranch
import Unison.Codebase.Editor.HandleInput.Merge2 qualified as Merge
import Unison.Codebase.Editor.Output qualified as Output
import Unison.Merge.TwoWay (TwoWay (..))
import Unison.Prelude
import Unison.Project (ProjectAndBranch (..))
handleCommitMerge :: Cli ()
handleCommitMerge :: Cli ()
handleCommitMerge = do
ProjectAndBranch Project ProjectBranch
mergeProjectAndBranch <- Cli (ProjectAndBranch Project ProjectBranch)
Cli.getCurrentProjectAndBranch
ProjectBranchId
parentBranchId <-
ProjectBranch -> Maybe ProjectBranchId
ProjectUtils.getMergeBranchParent ProjectAndBranch Project ProjectBranch
mergeProjectAndBranch.branch
Maybe ProjectBranchId
-> (Maybe ProjectBranchId -> Cli ProjectBranchId)
-> Cli ProjectBranchId
forall a b. a -> (a -> b) -> b
& Cli ProjectBranchId -> Maybe ProjectBranchId -> Cli ProjectBranchId
forall (m :: * -> *) a. Applicative m => m a -> Maybe a -> m a
onNothing (Output -> Cli ProjectBranchId
forall a. Output -> Cli a
Cli.returnEarly Output
Output.NoMergeInProgress)
ProjectBranch
parentBranch <-
Transaction ProjectBranch -> Cli ProjectBranch
forall a. Transaction a -> Cli a
Cli.runTransaction do
ProjectBranch
parentBranch <- ProjectId -> ProjectBranchId -> Transaction ProjectBranch
Queries.expectProjectBranch ProjectAndBranch Project ProjectBranch
mergeProjectAndBranch.project.projectId ProjectBranchId
parentBranchId
pure ProjectBranch
parentBranch
ProjectAndBranch ProjectId ProjectBranchId -> Cli ()
Cli.switchProject (ProjectId
-> ProjectBranchId -> ProjectAndBranch ProjectId ProjectBranchId
forall a b. a -> b -> ProjectAndBranch a b
ProjectAndBranch ProjectBranch
parentBranch.projectId ProjectBranch
parentBranch.branchId)
TwoWay (ProjectAndBranch Project ProjectBranch) -> Cli ()
Merge.doMergeLocalBranch
TwoWay
{ $sel:alice:TwoWay :: ProjectAndBranch Project ProjectBranch
alice = Project -> ProjectBranch -> ProjectAndBranch Project ProjectBranch
forall a b. a -> b -> ProjectAndBranch a b
ProjectAndBranch ProjectAndBranch Project ProjectBranch
mergeProjectAndBranch.project ProjectBranch
parentBranch,
$sel:bob:TwoWay :: ProjectAndBranch Project ProjectBranch
bob = ProjectAndBranch Project ProjectBranch
mergeProjectAndBranch
}
HasCallStack => ProjectAndBranch Project ProjectBranch -> Cli ()
ProjectAndBranch Project ProjectBranch -> Cli ()
DeleteBranch.doDeleteProjectBranch ProjectAndBranch Project ProjectBranch
mergeProjectAndBranch