Add basic success and failure messages

This commit is contained in:
Travis Staton 2024-03-18 13:54:03 -04:00
parent 38706cd5e3
commit 9694d8114d
No known key found for this signature in database
GPG Key ID: 431DD911A00DAE49
5 changed files with 47 additions and 5 deletions

View File

@ -72,7 +72,7 @@ import Unison.Parser.Ann (Ann)
import Unison.Prelude
import Unison.PrettyPrintEnv.Names qualified as PPE
import Unison.PrettyPrintEnvDecl.Names qualified as PPED
import Unison.Project (ProjectAndBranch (..), ProjectBranchName)
import Unison.Project (ProjectAndBranch (..), ProjectBranchName, ProjectName)
import Unison.Reference qualified as Reference
import Unison.Referent (Referent)
import Unison.Referent qualified as Referent
@ -175,6 +175,21 @@ handleMerge bobBranchName = do
( Path.unabsolute mergeInfo.paths.alice,
const mergedBranchPlusTuf
)
Cli.respond (Output.MergeSuccess (aliceProjectAndBranchName mergeInfo) (bobProjectAndBranchName mergeInfo))
aliceProjectAndBranchName :: MergeInfo -> ProjectAndBranch ProjectName ProjectBranchName
aliceProjectAndBranchName mergeInfo =
ProjectAndBranch
{ project = view (#project . #name) mergeInfo,
branch = view (#projectBranches . #alice . #name) mergeInfo
}
bobProjectAndBranchName :: MergeInfo -> ProjectAndBranch ProjectName ProjectBranchName
bobProjectAndBranchName mergeInfo =
ProjectAndBranch
{ project = view (#project . #name) mergeInfo,
branch = view (#projectBranches . #bob . #name) mergeInfo
}
------------------------------------------------------------------------------------------------------------------------
-- Loading basic info out of the database
@ -639,8 +654,7 @@ promptUser mergeInfo prettyUnisonFile newBranch = do
Nothing -> "scratch.u"
Just (file, _) -> file
liftIO $ writeSource (Text.pack scratchFilePath) (Text.pack $ Pretty.toPlain 80 prettyUnisonFile)
-- todo: respond with some message
Cli.returnEarlyWithoutOutput
Cli.returnEarly (Output.MergeFailure scratchFilePath (aliceProjectAndBranchName mergeInfo) (bobProjectAndBranchName mergeInfo))
findTemporaryBranchName :: ProjectId -> ProjectBranchName -> ProjectBranchName -> Transaction ProjectBranchName
findTemporaryBranchName projectId other self = do

View File

@ -394,6 +394,8 @@ data Output
| UpdateIncompleteConstructorSet UpdateOrUpgrade Name (Map ConstructorId Name) (Maybe Int)
| UpgradeFailure !FilePath !NameSegment !NameSegment
| UpgradeSuccess !NameSegment !NameSegment
| MergeFailure !FilePath !(ProjectAndBranch ProjectName ProjectBranchName) !(ProjectAndBranch ProjectName ProjectBranchName)
| MergeSuccess !(ProjectAndBranch ProjectName ProjectBranchName) !(ProjectAndBranch ProjectName ProjectBranchName)
| -- These are all merge precondition violations. See PreconditionViolation for more docs.
MergeConflictedAliases !ProjectBranchName !Name !Name
| MergeConflictedTermName !Name !(Set Referent)
@ -633,6 +635,8 @@ isFailure o = case o of
ProjectHasNoReleases {} -> True
UpgradeFailure {} -> True
UpgradeSuccess {} -> False
MergeFailure {} -> True
MergeSuccess {} -> False
MergeConflictedAliases {} -> True
MergeConflictedTermName {} -> True
MergeConflictedTypeName {} -> True

View File

@ -2251,6 +2251,20 @@ notifyUser dir = \case
<> P.group (P.text (NameSegment.toEscapedText new) <> ",")
<> "and removed"
<> P.group (P.text (NameSegment.toEscapedText old) <> ".")
MergeFailure path base target ->
pure . P.wrap $
"I couldn't automatically merge"
<> prettyProjectAndBranchName target
<> "into"
<> P.group (prettyProjectAndBranchName base <> ".")
<> "However, I've added the definitions that need attention to the top of"
<> P.group (prettyFilePath path <> ".")
MergeSuccess base target ->
pure . P.wrap $
"I merged"
<> prettyProjectAndBranchName target
<> "into"
<> P.group (prettyProjectAndBranchName base <> ".")
where
_nameChange _cmd _pastTenseCmd _oldName _newName _r = error "todo"

View File

@ -57,7 +57,7 @@ foo : Nat
foo = 4
```
```ucm
```ucm:error
proj/main> add
proj/main> merge2 /topic
```
@ -111,7 +111,7 @@ proj/main> update
attempt to merge `topic` into `main`
```ucm
```ucm:error
proj/main> merge2 /topic
```

View File

@ -62,6 +62,8 @@ proj/topic> add
proj/main> merge2 /topic
I merged proj/topic into proj/main.
proj/main> view bar
bar : Nat
@ -125,6 +127,10 @@ proj/main> add
proj/main> merge2 /topic
I couldn't automatically merge proj/topic into proj/main.
However, I've added the definitions that need attention to the
top of scratch.u.
```
```unison:added-by-ucm scratch.u
foo : Nat
@ -234,6 +240,10 @@ attempt to merge `topic` into `main`
```ucm
proj/main> merge2 /topic
I couldn't automatically merge proj/topic into proj/main.
However, I've added the definitions that need attention to the
top of scratch.u.
```
```unison:added-by-ucm scratch.u
bar : Nat