diff --git a/codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs b/codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs index f96ce2517b..ffb2b859cd 100644 --- a/codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs +++ b/codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs @@ -149,6 +149,7 @@ module U.Codebase.Sqlite.Queries setRemoteProjectBranchName, insertBranchRemoteMapping, ensureBranchRemoteMapping, + deleteBranchRemoteMapping, -- * indexes @@ -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"]) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs index 755737a825..2825914bfa 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs @@ -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 diff --git a/unison-cli/src/Unison/Codebase/Editor/Output.hs b/unison-cli/src/Unison/Codebase/Editor/Output.hs index 1b08b1ea1b..2cc685a29c 100644 --- a/unison-cli/src/Unison/Codebase/Editor/Output.hs +++ b/unison-cli/src/Unison/Codebase/Editor/Output.hs @@ -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 @@ -590,6 +591,7 @@ isFailure o = case o of LocalProjectNorProjectBranchExist {} -> True RemoteProjectDoesntExist {} -> True RemoteProjectBranchDoesntExist {} -> True + RemoteProjectBranchDoesntExist'Push {} -> True RemoteProjectReleaseIsDeprecated {} -> True RemoteProjectPublishedReleaseCannotBeChanged {} -> True RemoteProjectBranchHeadMismatch {} -> True diff --git a/unison-cli/src/Unison/CommandLine/OutputMessages.hs b/unison-cli/src/Unison/CommandLine/OutputMessages.hs index e41b0ced0d..f2775f0e79 100644 --- a/unison-cli/src/Unison/CommandLine/OutputMessages.hs +++ b/unison-cli/src/Unison/CommandLine/OutputMessages.hs @@ -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