Skip to content

Commit

Permalink
Merge pull request #4648 from unisonweb/travis/invalid-remote-mappings
Browse files Browse the repository at this point in the history
Delete invalid remote mappings on push
  • Loading branch information
aryairani authored Jan 29, 2024
2 parents d2bb44f + d96f8b9 commit 10724f7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
15 changes: 15 additions & 0 deletions codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ module U.Codebase.Sqlite.Queries
setRemoteProjectBranchName,
insertBranchRemoteMapping,
ensureBranchRemoteMapping,
deleteBranchRemoteMapping,

-- * indexes

Expand Down Expand Up @@ -4034,6 +4035,20 @@ ensureBranchRemoteMapping pid bid rpid host rbid =
DO NOTHING
|]

deleteBranchRemoteMapping ::
ProjectId ->
ProjectBranchId ->
URI ->
Transaction ()
deleteBranchRemoteMapping pid bid host =
execute
[sql|
DELETE FROM project_branch_remote_mapping
WHERE local_project_id = :pid
AND local_branch_id = :bid
AND remote_host = :host
|]

-- | Convert reversed name segments into glob for searching based on suffix
--
-- >>> toSuffixGlob ("foo" NonEmpty.:| ["bar"])
Expand Down
9 changes: 7 additions & 2 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,14 @@ pushProjectBranchToProjectBranch'InferredProject force localProjectAndBranch loc
(ProjectAndBranch (remoteProjectId, remoteProjectName) remoteBranchName)
-- "push" with remote mapping for branch
Just (remoteBranchId, remoteBranchName) -> do
let remoteProjectBranchDoesntExist =
let remoteProjectBranchDoesntExist = do
Cli.runTransaction $
Queries.deleteBranchRemoteMapping
localProjectId
localBranchId
Share.hardCodedUri
Cli.returnEarly $
Output.RemoteProjectBranchDoesntExist
Output.RemoteProjectBranchDoesntExist'Push
Share.hardCodedUri
(ProjectAndBranch remoteProjectName remoteBranchName)
Share.getProjectBranchById Share.NoSquashedHead (ProjectAndBranch remoteProjectId remoteBranchId) >>= \case
Expand Down
2 changes: 2 additions & 0 deletions unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ data Output
| LocalProjectNorProjectBranchExist ProjectName ProjectBranchName
| RemoteProjectDoesntExist URI ProjectName
| RemoteProjectBranchDoesntExist URI (ProjectAndBranch ProjectName ProjectBranchName)
| RemoteProjectBranchDoesntExist'Push URI (ProjectAndBranch ProjectName ProjectBranchName)
| RemoteProjectReleaseIsDeprecated URI (ProjectAndBranch ProjectName ProjectBranchName)
| RemoteProjectPublishedReleaseCannotBeChanged URI (ProjectAndBranch ProjectName ProjectBranchName)
| -- A remote project branch head wasn't in the expected state
Expand Down Expand Up @@ -590,6 +591,7 @@ isFailure o = case o of
LocalProjectNorProjectBranchExist {} -> True
RemoteProjectDoesntExist {} -> True
RemoteProjectBranchDoesntExist {} -> True
RemoteProjectBranchDoesntExist'Push {} -> True
RemoteProjectReleaseIsDeprecated {} -> True
RemoteProjectPublishedReleaseCannotBeChanged {} -> True
RemoteProjectBranchHeadMismatch {} -> True
Expand Down
11 changes: 11 additions & 0 deletions unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,17 @@ notifyUser dir = \case
RemoteProjectBranchDoesntExist host projectAndBranch ->
pure . P.wrap $
prettyProjectAndBranchName projectAndBranch <> "does not exist on" <> prettyURI host
RemoteProjectBranchDoesntExist'Push host projectAndBranch ->
let push = P.group . P.backticked . IP.patternName $ IP.push
in pure . P.wrap $
"The previous push target named"
<> prettyProjectAndBranchName projectAndBranch
<> "has been deleted from"
<> P.group (prettyURI host <> ".")
<> "I've deleted the invalid push target."
<> "Run the"
<> push
<> "command again to push to a new target."
RemoteProjectBranchHeadMismatch host projectAndBranch ->
pure . P.wrap $
prettyProjectAndBranchName projectAndBranch
Expand Down

0 comments on commit 10724f7

Please sign in to comment.