diff --git a/unison-cli/src/Unison/Cli/Share/Projects.hs b/unison-cli/src/Unison/Cli/Share/Projects.hs index ce03fb123..cd5942a94 100644 --- a/unison-cli/src/Unison/Cli/Share/Projects.hs +++ b/unison-cli/src/Unison/Cli/Share/Projects.hs @@ -111,7 +111,8 @@ onGetProjectResponse = \case onGetProjectBranchResponse :: GetProjectBranchResponse -> Cli () onGetProjectBranchResponse = \case - GetProjectBranchResponseNotFound {} -> pure () + GetProjectBranchResponseBranchNotFound {} -> pure () + GetProjectBranchResponseProjectNotFound {} -> pure () GetProjectBranchResponseUnauthorized {} -> pure () GetProjectBranchResponseSuccess branch -> onProjectBranch branch diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/ProjectClone.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/ProjectClone.hs index c75638532..0238cff80 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/ProjectClone.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/ProjectClone.hs @@ -58,9 +58,12 @@ projectClone projectName = do let remoteProjectId = RemoteProjectId (project ^. #projectId) let remoteBranchName = unsafeFrom @Text "main" Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case - Share.API.GetProjectBranchResponseNotFound notFound -> do + Share.API.GetProjectBranchResponseBranchNotFound notFound -> do loggeth ["remote branch 'main' doesn't exist: ", tShow notFound] Cli.returnEarlyWithoutOutput + Share.API.GetProjectBranchResponseProjectNotFound notFound -> do + loggeth ["project doesn't exist: ", tShow notFound] + Cli.returnEarlyWithoutOutput Share.API.GetProjectBranchResponseUnauthorized unauthorized -> do loggeth ["unauthorized: ", tShow unauthorized] Cli.returnEarlyWithoutOutput diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs index 5ccb0cbfa..e7ba4c8ec 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs @@ -368,8 +368,11 @@ bazinga50 localProjectAndBranch localBranchHead maybeRemoteBranchName = -- "push" with remote mapping for branch Just remoteBranchId -> Share.getProjectBranchById (ProjectAndBranch remoteProjectId remoteBranchId) >>= \case - Share.API.GetProjectBranchResponseNotFound (Share.API.NotFound msg) -> do - loggeth ["project or branch deleted on Share: " <> msg] + Share.API.GetProjectBranchResponseBranchNotFound (Share.API.NotFound msg) -> do + loggeth ["branch deleted on Share: " <> msg] + Cli.returnEarlyWithoutOutput + Share.API.GetProjectBranchResponseProjectNotFound (Share.API.NotFound msg) -> do + loggeth ["branch deleted on Share: " <> msg] Cli.returnEarlyWithoutOutput Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined Share.API.GetProjectBranchResponseSuccess remoteBranch -> do @@ -435,7 +438,7 @@ pushToProjectBranch0 pushing localBranchHead remoteProjectAndBranch = do Share.API.GetProjectResponseSuccess remoteProject -> do let remoteProjectId = RemoteProjectId (remoteProject ^. #projectId) Share.getProjectBranchByName (ProjectAndBranch remoteProjectId remoteBranchName) >>= \case - Share.API.GetProjectBranchResponseNotFound {} -> do + Share.API.GetProjectBranchResponseBranchNotFound {} -> do pure UploadPlan { repoName, @@ -446,6 +449,7 @@ pushToProjectBranch0 pushing localBranchHead remoteProjectAndBranch = do localBranchHead (ProjectAndBranch (RemoteProjectId (remoteProject ^. #projectId)) remoteBranchName) } + Share.API.GetProjectBranchResponseProjectNotFound {} -> wundefined Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined Share.API.GetProjectBranchResponseSuccess remoteBranch -> do afterUploadAction <- makeFastForwardAfterUploadAction pushing localBranchHead remoteBranch @@ -472,8 +476,7 @@ pushToProjectBranch1 localProjectAndBranch localBranchHead remoteProjectAndBranc Share.API.GetProjectResponseSuccess remoteProject -> expectRemoteProjectRepoName remoteProject Just userSlug -> pure (Share.RepoName userSlug) Share.getProjectBranchByName remoteProjectAndBranch >>= \case - Share.API.GetProjectBranchResponseNotFound {} -> do - -- FIXME check to see if the project exists here instead of assuming it does + Share.API.GetProjectBranchResponseBranchNotFound {} -> do pure UploadPlan { repoName, @@ -484,6 +487,7 @@ pushToProjectBranch1 localProjectAndBranch localBranchHead remoteProjectAndBranc localBranchHead remoteProjectAndBranch } + Share.API.GetProjectBranchResponseProjectNotFound {} -> wundefined Share.API.GetProjectBranchResponseUnauthorized {} -> wundefined Share.API.GetProjectBranchResponseSuccess remoteBranch -> do afterUploadAction <- diff --git a/unison-share-projects-api/src/Unison/Share/API/Projects.hs b/unison-share-projects-api/src/Unison/Share/API/Projects.hs index 4f1996e6d..deab49878 100644 --- a/unison-share-projects-api/src/Unison/Share/API/Projects.hs +++ b/unison-share-projects-api/src/Unison/Share/API/Projects.hs @@ -152,7 +152,8 @@ type GetProjectBranchAPI = -- | @GET /project-branch@ response. data GetProjectBranchResponse - = GetProjectBranchResponseNotFound NotFound + = GetProjectBranchResponseProjectNotFound NotFound + | GetProjectBranchResponseBranchNotFound NotFound | GetProjectBranchResponseUnauthorized Unauthorized | GetProjectBranchResponseSuccess !ProjectBranch deriving stock (Eq, Show, Generic) @@ -161,14 +162,16 @@ instance FromJSON GetProjectBranchResponse where parseJSON = withSumType "GetProjectBranchResponse" \typ val -> case typ of - "not-found" -> GetProjectBranchResponseNotFound <$> parseJSON val + "project-not-found" -> GetProjectBranchResponseProjectNotFound <$> parseJSON val + "branch-not-found" -> GetProjectBranchResponseBranchNotFound <$> parseJSON val "unauthorized" -> GetProjectBranchResponseUnauthorized <$> parseJSON val "success" -> GetProjectBranchResponseSuccess <$> parseJSON val _ -> fail (Text.unpack ("unknown GetProjectBranchResponse type: " <> typ)) instance ToJSON GetProjectBranchResponse where toJSON = \case - GetProjectBranchResponseNotFound notFound -> toSumType "not-found" (toJSON notFound) + GetProjectBranchResponseProjectNotFound notFound -> toSumType "project-not-found" (toJSON notFound) + GetProjectBranchResponseBranchNotFound notFound -> toSumType "branch-not-found" (toJSON notFound) GetProjectBranchResponseUnauthorized unauthorized -> toSumType "unauthorized" (toJSON unauthorized) GetProjectBranchResponseSuccess branch -> toSumType "success" (toJSON branch)