diff --git a/R/github.R b/R/github.R index 818366202..1727a187c 100644 --- a/R/github.R +++ b/R/github.R @@ -268,21 +268,23 @@ check_no_origin <- function() { } check_no_github_repo <- function(owner, repo, host) { + spec <- glue("{owner}/{repo}") repo_found <- tryCatch( { - repo_info <- gh::gh( - "/repos/{owner}/{repo}", - owner = owner, repo = repo, - .api_url = host - ) - TRUE + repo_info <- gh::gh("/repos/{spec}", spec = spec, .api_url = host) + # when does repo_info$full_name != the spec we sent? + # this happens if you reuse the original name of a repo that has since + # been renamed + # there's no 404, because of the automatic redirect, but you CAN create + # a new repo with this name + # https://github.com/r-lib/usethis/issues/1893 + repo_info$full_name == spec }, "http_error_404" = function(err) FALSE ) if (!repo_found) { return(invisible()) } - spec <- glue("{owner}/{repo}") empirical_host <- parse_github_remotes(repo_info$html_url)$host ui_stop("Repo {ui_value(spec)} already exists on {ui_value(empirical_host)}") }