@@ -239,8 +239,9 @@ use_github_links <- function(auth_token = deprecated(),
239239 invisible ()
240240}
241241
242- has_github_links <- function () {
243- github_url <- github_url_from_git_remotes()
242+ has_github_links <- function (target_repo = NULL ) {
243+ url <- if (is.null(target_repo )) NULL else target_repo $ url
244+ github_url <- github_url_from_git_remotes(url )
244245 if (is.null(github_url )) {
245246 return (FALSE )
246247 }
@@ -269,21 +270,23 @@ check_no_origin <- function() {
269270}
270271
271272check_no_github_repo <- function (owner , repo , host ) {
273+ spec <- glue(" {owner}/{repo}" )
272274 repo_found <- tryCatch(
273275 {
274- repo_info <- gh :: gh(
275- " /repos/{owner}/{repo}" ,
276- owner = owner , repo = repo ,
277- .api_url = host
278- )
279- TRUE
276+ repo_info <- gh :: gh(" /repos/{spec}" , spec = spec , .api_url = host )
277+ # when does repo_info$full_name != the spec we sent?
278+ # this happens if you reuse the original name of a repo that has since
279+ # been renamed
280+ # there's no 404, because of the automatic redirect, but you CAN create
281+ # a new repo with this name
282+ # https://github.com/r-lib/usethis/issues/1893
283+ repo_info $ full_name == spec
280284 },
281285 " http_error_404" = function (err ) FALSE
282286 )
283287 if (! repo_found ) {
284288 return (invisible ())
285289 }
286- spec <- glue(" {owner}/{repo}" )
287290 empirical_host <- parse_github_remotes(repo_info $ html_url )$ host
288291 ui_abort(" Repo {.val {spec}} already exists on {.val {empirical_host}}." )
289292}
0 commit comments