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