Don't allow absolute paths in delete.namespace

This commit is contained in:
Chris Penner 2024-05-22 11:51:10 -07:00
parent b210679917
commit f25a221c25
5 changed files with 24 additions and 15 deletions

View File

@ -744,16 +744,15 @@ loop e = do
Cli.respond DeletedEverything
else Cli.respond DeleteEverythingConfirmation
DeleteTarget'Namespace insistence (Just p@(parentPath, childName)) -> do
branch <- Cli.expectBranchAtPath' (Path.unsplit' p)
branch <- Cli.expectBranchAtPath (Path.unsplit p)
description <- inputDescription input
absPath <- Cli.resolveSplit' p
let toDelete =
Names.prefix0
(Path.unsafeToName (Path.unsplit (Path.convert absPath)))
(Path.unsafeToName (Path.unsplit (p)))
(Branch.toNames (Branch.head branch))
afterDelete <- do
rootNames <- Branch.toNames <$> Cli.getRootBranch0
endangerments <- Cli.runTransaction (getEndangeredDependents toDelete Set.empty rootNames)
names <- Cli.currentNames
endangerments <- Cli.runTransaction (getEndangeredDependents toDelete Set.empty names)
case (null endangerments, insistence) of
(True, _) -> pure (Cli.respond Success)
(False, Force) -> do
@ -765,7 +764,7 @@ loop e = do
ppeDecl <- Cli.currentPrettyPrintEnvDecl
Cli.respondNumbered $ CantDeleteNamespace ppeDecl endangerments
Cli.returnEarlyWithoutOutput
parentPathAbs <- Cli.resolvePath' parentPath
parentPathAbs <- Cli.resolvePath parentPath
-- We have to modify the parent in order to also wipe out the history at the
-- child.
Cli.updateAt description parentPathAbs \parentBranch ->
@ -1274,10 +1273,10 @@ inputDescription input =
thing <- traverse hqs' thing0
pure ("delete.type.verbose " <> Text.intercalate " " thing)
DeleteTarget'Namespace Try opath0 -> do
opath <- ops' opath0
opath <- ops opath0
pure ("delete.namespace " <> opath)
DeleteTarget'Namespace Force opath0 -> do
opath <- ops' opath0
opath <- ops opath0
pure ("delete.namespace.force " <> opath)
DeleteTarget'Patch path0 -> do
path <- ps' path0
@ -1410,8 +1409,8 @@ inputDescription input =
p' = fmap tShow . Cli.resolvePath'
brp :: BranchRelativePath -> Cli Text
brp = fmap from . ProjectUtils.resolveBranchRelativePath
ops' :: Maybe Path.Split' -> Cli Text
ops' = maybe (pure ".") ps'
ops :: Maybe Path.Split -> Cli Text
ops = maybe (pure ".") ps
opatch :: Maybe Path.Split' -> Cli Text
opatch = ps' . fromMaybe Cli.defaultPatchPath
wat = error $ show input ++ " is not expected to alter the branch"
@ -1425,6 +1424,7 @@ inputDescription input =
pure (p <> "." <> HQ'.toTextWith NameSegment.toEscapedText hq)
hqs (p, hq) = hqs' (Path' . Right . Path.Relative $ p, hq)
ps' = p' . Path.unsplit'
ps = p . Path.unsplit
looseCodeOrProjectToText :: Input.LooseCodeOrProject -> Cli Text
looseCodeOrProjectToText = \case
This path -> p' path

View File

@ -331,7 +331,7 @@ data DeleteTarget
= DeleteTarget'TermOrType DeleteOutput [Path.HQSplit']
| DeleteTarget'Term DeleteOutput [Path.HQSplit']
| DeleteTarget'Type DeleteOutput [Path.HQSplit']
| DeleteTarget'Namespace Insistence (Maybe Path.Split')
| DeleteTarget'Namespace Insistence (Maybe Path.Split)
| DeleteTarget'Patch Path.Split'
| DeleteTarget'ProjectBranch (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
| DeleteTarget'Project ProjectName

View File

@ -1239,7 +1239,7 @@ deleteNamespaceParser helpText insistence = \case
. pure
$ Input.DeleteI (DeleteTarget'Namespace insistence Nothing)
[p] -> first P.text do
p <- Path.parseSplit' p
p <- Path.parseSplit p
pure $ Input.DeleteI (DeleteTarget'Namespace insistence (Just p))
_ -> Left helpText

View File

@ -15,7 +15,7 @@ sub.dependency = 123
dependent = dependency + 99
```
```ucm
```ucm:error
myproject/main> add
myproject/main> branch /new
myproject/new> delete.namespace sub

View File

@ -41,13 +41,22 @@ myproject/main> branch /new
myproject/new> delete.namespace sub
Done.
⚠️
I didn't delete the namespace because the following
definitions are still in use.
Dependency Referenced In
dependency 1. dependent
If you want to proceed anyways and leave those definitions
without names, use delete.namespace.force
myproject/new> view dependent
dependent : Nat
dependent =
use Nat +
#mllb0u5378 + 99
dependency + 99
```