Skip to content

Commit

Permalink
Merge pull request #4505 from unisonweb/tweak-branch-exists-error-mes…
Browse files Browse the repository at this point in the history
…sage

fix "branch already exists" error message to show project, too
  • Loading branch information
aryairani authored Dec 21, 2023
2 parents 0eead8b + b7da721 commit 5e98e80
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
39 changes: 38 additions & 1 deletion lib/unison-prelude/src/Unison/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ module Unison.Prelude
tShow,
wundefined,

-- * @Bool@ control flow
onFalse,
onFalseM,
onTrue,
onTrueM,

-- * @Maybe@ control flow
onNothing,
onNothingM,
Expand Down Expand Up @@ -53,7 +59,8 @@ import Data.Foldable as X (fold, foldl', for_, toList, traverse_)
import Data.Function as X ((&))
import Data.Functor as X
import Data.Functor.Identity as X
import Data.Generics.Labels () -- #labelSyntax for generics-derived lenses
-- #labelSyntax for generics-derived lenses
import Data.Generics.Labels ()
import Data.Int as X
import Data.List as X (foldl1', sortOn)
import Data.Map as X (Map)
Expand Down Expand Up @@ -93,6 +100,36 @@ altSum = foldl' (<|>) empty
altMap :: (Alternative f, Foldable t) => (a -> f b) -> t a -> f b
altMap f = altSum . fmap f . toList

-- |
-- > condition & onFalse do
-- > shortCircuit
onFalse :: (Applicative m) => m () -> Bool -> m ()
onFalse action = \case
False -> action
True -> pure ()

-- |
-- > action & onFalseM do
-- > shortCircuit
onFalseM :: (Monad m) => m () -> m Bool -> m ()
onFalseM x y =
y >>= onFalse x

-- |
-- > condition & onTrue do
-- > shortCircuit
onTrue :: (Applicative m) => m () -> Bool -> m ()
onTrue action = \case
True -> action
False -> pure ()

-- |
-- > action & onTrueM do
-- > shortCircuit
onTrueM :: (Monad m) => m () -> m Bool -> m ()
onTrueM x y =
y >>= onTrue x

-- | E.g.
--
-- @@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ assertLocalProjectBranchDoesntExist rollback = \case
Just project -> go project branchName
ProjectAndBranch (LocalProjectKey'Project project) branchName -> go project branchName
where
go project branchName =
Queries.projectBranchExistsByName (project ^. #projectId) branchName >>= \case
False -> pure (Right project)
True -> rollback (Output.ProjectAndBranchNameAlreadyExists (ProjectAndBranch (project ^. #name) branchName))
go project branchName = do
Queries.projectBranchExistsByName (project ^. #projectId) branchName & onTrueM do
rollback (Output.ProjectAndBranchNameAlreadyExists (ProjectAndBranch (project ^. #name) branchName))
pure (Right project)
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ notifyUser dir = \case
prettyProjectAndBranchName projectAndBranch
<> "already exists."
<> "You can switch to it with "
<> IP.makeExampleEOS IP.projectSwitch [prettyBranchName projectAndBranch]
<> IP.makeExampleEOS IP.projectSwitch [prettyProjectAndBranchName projectAndBranch]
NotOnProjectBranch -> pure (P.wrap "You are not currently on a branch.")
NoAssociatedRemoteProject host projectAndBranch ->
pure . P.wrap $
Expand Down
2 changes: 1 addition & 1 deletion unison-src/transcripts/release-draft-command.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ It's an error to try to create a `releases/drafts/x.y.z` branch that already exi
foo/main> release.draft 1.2.3
foo/releases/drafts/1.2.3 already exists. You can switch to it
with `switch /releases/drafts/1.2.3`.
with `switch foo/releases/drafts/1.2.3`.
```

0 comments on commit 5e98e80

Please sign in to comment.