mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 02:25:39 +03:00
Mostly Fix up deleting the branch you're on
This commit is contained in:
parent
e9f2aa3ec5
commit
2331c16770
@ -3871,7 +3871,7 @@ deleteProject projectId = do
|
||||
-- After deleting `topic`:
|
||||
--
|
||||
-- main <- topic2
|
||||
deleteProjectBranch :: ProjectId -> ProjectBranchId -> Transaction ()
|
||||
deleteProjectBranch :: (HasCallStack) => ProjectId -> ProjectBranchId -> Transaction ()
|
||||
deleteProjectBranch projectId branchId = do
|
||||
maybeParentBranchId :: Maybe ProjectBranchId <-
|
||||
queryMaybeCol
|
||||
|
@ -5,6 +5,7 @@ module Unison.Codebase.Editor.HandleInput.DeleteBranch
|
||||
)
|
||||
where
|
||||
|
||||
import Data.List qualified as List
|
||||
import U.Codebase.Sqlite.DbId (ProjectBranchId, ProjectId)
|
||||
import U.Codebase.Sqlite.Project qualified as Sqlite
|
||||
import U.Codebase.Sqlite.ProjectBranch qualified as Sqlite
|
||||
@ -41,11 +42,13 @@ handleDeleteBranch projectAndBranchNamesToDelete = do
|
||||
Cli.runTransaction . runMaybeT $
|
||||
asum
|
||||
[ parentBranch (branchToDelete ^. #projectId) (branchToDelete ^. #parentBranchId),
|
||||
findMainBranchInProject (currentProject ^. #projectId),
|
||||
findAnyBranchInProject (currentProject ^. #projectId),
|
||||
findAnyBranchInCodebase,
|
||||
findMainBranchInProjectExcept (currentProject ^. #projectId) (branchToDelete ^. #branchId),
|
||||
-- Any branch in the codebase except the one we're deleting
|
||||
findAnyBranchInProjectExcept (branchToDelete ^. #projectId) (branchToDelete ^. #branchId),
|
||||
findAnyBranchInCodebaseExcept (branchToDelete ^. #projectId) (branchToDelete ^. #branchId),
|
||||
createDummyProject
|
||||
]
|
||||
|
||||
nextLoc <- mayNextLocation `whenNothing` projectCreate False Nothing
|
||||
Cli.switchProject nextLoc
|
||||
doDeleteProjectBranch projectAndBranchToDelete
|
||||
@ -54,23 +57,24 @@ handleDeleteBranch projectAndBranchNamesToDelete = do
|
||||
parentBranch projectId mayParentBranchId = do
|
||||
parentBranchId <- hoistMaybe mayParentBranchId
|
||||
pure (ProjectAndBranch projectId parentBranchId)
|
||||
findMainBranchInProject :: ProjectId -> MaybeT Sqlite.Transaction (ProjectAndBranch ProjectId ProjectBranchId)
|
||||
findMainBranchInProject projectId = do
|
||||
findMainBranchInProjectExcept :: ProjectId -> ProjectBranchId -> MaybeT Sqlite.Transaction (ProjectAndBranch ProjectId ProjectBranchId)
|
||||
findMainBranchInProjectExcept projectId exceptBranchId = do
|
||||
branch <- MaybeT $ Queries.loadProjectBranchByName projectId (unsafeFrom @Text "main")
|
||||
guard (branch ^. #branchId /= exceptBranchId)
|
||||
pure (ProjectAndBranch projectId (branch ^. #branchId))
|
||||
|
||||
findAnyBranchInProject :: ProjectId -> MaybeT Sqlite.Transaction (ProjectAndBranch ProjectId ProjectBranchId)
|
||||
findAnyBranchInProject projectId = do
|
||||
(someBranchId, _) <- MaybeT . fmap listToMaybe $ Queries.loadAllProjectBranchesBeginningWith projectId Nothing
|
||||
findAnyBranchInProjectExcept :: ProjectId -> ProjectBranchId -> MaybeT Sqlite.Transaction (ProjectAndBranch ProjectId ProjectBranchId)
|
||||
findAnyBranchInProjectExcept projectId exceptBranchId = do
|
||||
(someBranchId, _) <- MaybeT . fmap (List.find (\(branchId, _) -> branchId /= exceptBranchId)) $ Queries.loadAllProjectBranchesBeginningWith projectId Nothing
|
||||
pure (ProjectAndBranch projectId someBranchId)
|
||||
findAnyBranchInCodebase :: MaybeT Sqlite.Transaction (ProjectAndBranch ProjectId ProjectBranchId)
|
||||
findAnyBranchInCodebase = do
|
||||
(_, pbIds) <- MaybeT . fmap listToMaybe $ Queries.loadAllProjectBranchNamePairs
|
||||
findAnyBranchInCodebaseExcept :: ProjectId -> ProjectBranchId -> MaybeT Sqlite.Transaction (ProjectAndBranch ProjectId ProjectBranchId)
|
||||
findAnyBranchInCodebaseExcept exceptProjectId exceptBranchId = do
|
||||
(_, pbIds) <- MaybeT . fmap (List.find (\(_, ids) -> ids /= ProjectAndBranch exceptProjectId exceptBranchId)) $ Queries.loadAllProjectBranchNamePairs
|
||||
pure pbIds
|
||||
createDummyProject = error "TODO: create new branch or project if we delete the last branch you're on."
|
||||
|
||||
-- | Delete a project branch and record an entry in the reflog.
|
||||
doDeleteProjectBranch :: ProjectAndBranch Sqlite.Project Sqlite.ProjectBranch -> Cli ()
|
||||
doDeleteProjectBranch :: (HasCallStack) => ProjectAndBranch Sqlite.Project Sqlite.ProjectBranch -> Cli ()
|
||||
doDeleteProjectBranch projectAndBranch = do
|
||||
Cli.runTransaction do
|
||||
Queries.deleteProjectBranch projectAndBranch.project.projectId projectAndBranch.branch.branchId
|
||||
|
@ -4,7 +4,6 @@ module Unison.Codebase.Editor.HandleInput.DeleteProject
|
||||
)
|
||||
where
|
||||
|
||||
import Data.Function (on)
|
||||
import U.Codebase.Sqlite.Queries qualified as Queries
|
||||
import Unison.Cli.Monad (Cli)
|
||||
import Unison.Cli.Monad qualified as Cli
|
||||
@ -20,16 +19,16 @@ handleDeleteProject :: ProjectName -> Cli ()
|
||||
handleDeleteProject projectName = do
|
||||
ProjectPath currentProject _ _ <- Cli.getCurrentProjectPath
|
||||
|
||||
deletedProject <-
|
||||
projectToDelete <-
|
||||
Cli.runTransactionWithRollback \rollback -> do
|
||||
project <-
|
||||
Queries.loadProjectByName projectName & onNothingM do
|
||||
rollback (Output.LocalProjectDoesntExist projectName)
|
||||
Queries.deleteProject (project ^. #projectId)
|
||||
pure project
|
||||
|
||||
-- If the user is on the project that they're deleting, we create a new project to switch
|
||||
-- to.
|
||||
when (((==) `on` (view #projectId)) deletedProject currentProject) do
|
||||
when ((projectToDelete ^. #projectId) == (currentProject ^. #projectId)) do
|
||||
nextLoc <- projectCreate False Nothing
|
||||
Cli.switchProject nextLoc
|
||||
|
||||
Cli.runTransaction do
|
||||
Queries.deleteProject (projectToDelete ^. #projectId)
|
||||
|
@ -25,3 +25,9 @@ You can delete the only branch in a project.
|
||||
```ucm
|
||||
foo/main> delete.branch /main
|
||||
```
|
||||
|
||||
You can delete the last branch in the codebase
|
||||
|
||||
```ucm
|
||||
scratch/main> delete.branch scratch/main
|
||||
```
|
||||
|
@ -43,7 +43,7 @@ scratch/main> projects
|
||||
foo/main> delete.project foo
|
||||
|
||||
🎉 I've created the project with the randomly-chosen name
|
||||
helpful-ladybug (use `project.rename <new-name>` to change
|
||||
outstanding-rhino (use `project.rename <new-name>` to change
|
||||
it).
|
||||
|
||||
🎨 Type `ui` to explore this project's code in your browser.
|
||||
@ -61,7 +61,7 @@ foo/main> delete.project foo
|
||||
scratch/main> projects
|
||||
|
||||
1. bar
|
||||
2. helpful-ladybug
|
||||
2. outstanding-rhino
|
||||
3. scratch
|
||||
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user