Merge pull request #5039 from unisonweb/24-05-20-upgrade-commit

This commit is contained in:
Arya Irani 2024-06-03 19:35:15 -04:00 committed by GitHub
commit 78dae4ff07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 109 additions and 20 deletions

View File

@ -22,7 +22,6 @@ module Unison.Cli.Pretty
prettyMergeSource,
prettyMergeSourceOrTarget,
prettyProjectAndBranchName,
prettyBranchName,
prettyProjectBranchName,
prettyProjectName,
prettyProjectNameSlash,
@ -272,9 +271,6 @@ prettyProjectAndBranchName :: ProjectAndBranch ProjectName ProjectBranchName ->
prettyProjectAndBranchName (ProjectAndBranch project branch) =
P.group (prettyProjectName project <> P.hiBlack "/" <> prettyProjectBranchName branch)
prettyBranchName :: ProjectAndBranch ProjectName ProjectBranchName -> Pretty
prettyBranchName (ProjectAndBranch _ branch) = prettySlashProjectBranchName branch
-- produces:
-- -- #5v5UtREE1fTiyTsTK2zJ1YNqfiF25SkfUnnji86Lms#0
-- Optional.None, Maybe.Nothing : Maybe a

View File

@ -11,6 +11,8 @@ import Data.Set qualified as Set
import Data.Text qualified as Text
import Text.Builder qualified
import U.Codebase.Sqlite.DbId (ProjectId)
import U.Codebase.Sqlite.Project qualified
import U.Codebase.Sqlite.ProjectBranch qualified
import Unison.Cli.Monad (Cli)
import Unison.Cli.Monad qualified as Cli
import Unison.Cli.MonadUtils qualified as Cli
@ -65,8 +67,8 @@ handleUpgrade oldName newName = do
Cli.Env {codebase, writeSource} <- ask
(projectAndBranch, _path) <- Cli.expectCurrentProjectBranch
let projectId = projectAndBranch ^. #project . #projectId
let projectPath = Cli.projectBranchPath (ProjectAndBranch projectId (projectAndBranch ^. #branch . #branchId))
let projectId = projectAndBranch.project.projectId
let projectPath = Cli.projectBranchPath (ProjectAndBranch projectId projectAndBranch.branch.branchId)
let oldPath = Path.resolve projectPath (Path.Relative (Path.fromList [NameSegment.libSegment, oldName]))
let newPath = Path.resolve projectPath (Path.Relative (Path.fromList [NameSegment.libSegment, newName]))
@ -159,7 +161,7 @@ handleUpgrade oldName newName = do
temporaryBranchId <-
HandleInput.Branch.doCreateBranch
(HandleInput.Branch.CreateFrom'Branch projectAndBranch)
(projectAndBranch ^. #project)
projectAndBranch.project
temporaryBranchName
textualDescriptionOfUpgrade
let temporaryBranchPath = Path.unabsolute (Cli.projectBranchPath (ProjectAndBranch projectId temporaryBranchId))
@ -169,7 +171,8 @@ handleUpgrade oldName newName = do
Nothing -> "scratch.u"
Just (file, _) -> file
liftIO $ writeSource (Text.pack scratchFilePath) (Text.pack $ Pretty.toPlain 80 prettyUnisonFile)
Cli.returnEarly (Output.UpgradeFailure scratchFilePath oldName newName)
Cli.returnEarly $
Output.UpgradeFailure projectAndBranch.branch.name temporaryBranchName scratchFilePath oldName newName
branchUpdates <-
Cli.runTransactionWithRollback \abort -> do

View File

@ -389,7 +389,7 @@ data Output
| UpdateTypecheckingFailure
| UpdateTypecheckingSuccess
| UpdateIncompleteConstructorSet UpdateOrUpgrade Name (Map ConstructorId Name) (Maybe Int)
| UpgradeFailure !FilePath !NameSegment !NameSegment
| UpgradeFailure !ProjectBranchName !ProjectBranchName !FilePath !NameSegment !NameSegment
| UpgradeSuccess !NameSegment !NameSegment
| LooseCodePushDeprecated
| MergeFailure !FilePath !MergeSourceAndTarget

View File

@ -157,7 +157,14 @@ import U.Codebase.Sqlite.DbId (ProjectBranchId)
import U.Codebase.Sqlite.Project qualified as Sqlite
import U.Codebase.Sqlite.Queries qualified as Queries
import Unison.Auth.HTTPClient (AuthenticatedHttpClient)
import Unison.Cli.Pretty (prettyProjectAndBranchName, prettyProjectName, prettyProjectNameSlash, prettySlashProjectBranchName, prettyURI)
import Unison.Cli.Pretty
( prettyProjectAndBranchName,
prettyProjectBranchName,
prettyProjectName,
prettyProjectNameSlash,
prettySlashProjectBranchName,
prettyURI,
)
import Unison.Cli.ProjectUtils qualified as ProjectUtils
import Unison.Codebase (Codebase)
import Unison.Codebase qualified as Codebase
@ -185,6 +192,7 @@ import Unison.CommandLine.Completion
import Unison.CommandLine.FZFResolvers qualified as Resolvers
import Unison.CommandLine.InputPattern (ArgumentType (..), InputPattern (InputPattern), IsOptional (..), unionSuggestions)
import Unison.CommandLine.InputPattern qualified as I
import Unison.Core.Project (ProjectBranchName (..))
import Unison.HashQualified qualified as HQ
import Unison.HashQualified' qualified as HQ'
import Unison.Name (Name)
@ -196,7 +204,6 @@ import Unison.Parser.Ann (Ann)
import Unison.Project
( ProjectAndBranch (..),
ProjectAndBranchNames (..),
ProjectBranchName,
ProjectBranchNameOrLatestRelease (..),
ProjectBranchSpecifier (..),
ProjectName,
@ -3148,7 +3155,36 @@ upgradeCommitInputPattern =
aliases = ["commit.upgrade"],
visibility = I.Visible,
args = [],
help = P.wrap $ makeExample' upgradeCommitInputPattern <> "commits the current upgrade.",
help =
let mainBranch = UnsafeProjectBranchName "main"
tempBranch = UnsafeProjectBranchName "upgrade-foo-to-bar"
in P.wrap
( makeExample' upgradeCommitInputPattern
<> "merges a temporary branch created by the"
<> makeExample' upgrade
<> "command back into its parent branch, and removes the temporary branch."
)
<> P.newline
<> P.newline
<> P.wrap
( "For example, if you've done"
<> makeExample upgrade ["foo", "bar"]
<> "from"
<> P.group (prettyProjectBranchName mainBranch <> ",")
<> "then"
<> makeExample' upgradeCommitInputPattern
<> "is equivalent to doing"
)
<> P.newline
<> P.newline
<> P.indentN
2
( P.bulleted
[ makeExampleNoBackticks projectSwitch [prettySlashProjectBranchName mainBranch],
makeExampleNoBackticks mergeInputPattern [prettySlashProjectBranchName tempBranch],
makeExampleNoBackticks deleteBranch [prettySlashProjectBranchName tempBranch]
]
),
parse = \case
[] -> Right Input.UpgradeCommitI
_ -> Left (I.help upgradeCommitInputPattern)

View File

@ -2035,14 +2035,32 @@ notifyUser dir = \case
<> operationName
<> "again."
]
UpgradeFailure path old new ->
pure . P.wrap $
"I couldn't automatically upgrade"
<> P.text (NameSegment.toEscapedText old)
<> "to"
<> P.group (P.text (NameSegment.toEscapedText new) <> ".")
<> "However, I've added the definitions that need attention to the top of"
<> P.group (prettyFilePath path <> ".")
UpgradeFailure main temp path old new ->
pure $
P.lines
[ P.wrap $
"I couldn't automatically upgrade"
<> P.text (NameSegment.toEscapedText old)
<> "to"
<> P.group (P.text (NameSegment.toEscapedText new) <> ".")
<> "However, I've added the definitions that need attention to the top of"
<> P.group (prettyFilePath path <> "."),
"",
P.wrap "When you're done, you can run",
"",
P.indentN 2 (IP.makeExampleNoBackticks IP.upgradeCommitInputPattern []),
"",
P.wrap $
"to merge your changes back into"
<> prettyProjectBranchName main
<> "and delete the temporary branch. Or, if you decide to cancel the upgrade instead, you can run",
"",
P.indentN 2 (IP.makeExampleNoBackticks IP.deleteBranch [prettySlashProjectBranchName temp]),
"",
P.wrap $
"to delete the temporary branch and switch back to"
<> P.group (prettyProjectBranchName main <> ".")
]
UpgradeSuccess old new ->
pure . P.wrap $
"I upgraded"

View File

@ -39,6 +39,18 @@ myproj/main> upgrade foo0 foo1
I couldn't automatically upgrade foo0 to foo1. However, I've
added the definitions that need attention to the top of
scratch.u.
When you're done, you can run
upgrade.commit
to merge your changes back into main and delete the temporary
branch. Or, if you decide to cancel the upgrade instead, you
can run
delete.branch /upgrade-foo0-to-foo1
to delete the temporary branch and switch back to main.
```
```unison:added-by-ucm scratch.u

View File

@ -35,6 +35,18 @@ proj/main> upgrade old new
I couldn't automatically upgrade old to new. However, I've
added the definitions that need attention to the top of
scratch.u.
When you're done, you can run
upgrade.commit
to merge your changes back into main and delete the temporary
branch. Or, if you decide to cancel the upgrade instead, you
can run
delete.branch /upgrade-old-to-new
to delete the temporary branch and switch back to main.
```
```unison:added-by-ucm scratch.u

View File

@ -47,6 +47,18 @@ myproject/main> upgrade old new
I couldn't automatically upgrade old to new. However, I've
added the definitions that need attention to the top of
scratch.u.
When you're done, you can run
upgrade.commit
to merge your changes back into main and delete the temporary
branch. Or, if you decide to cancel the upgrade instead, you
can run
delete.branch /upgrade-old-to-new
to delete the temporary branch and switch back to main.
```
```unison:added-by-ucm scratch.u