@@ -239,8 +239,9 @@ use_github_links <- function(auth_token = deprecated(),
239
239
invisible ()
240
240
}
241
241
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 )
244
245
if (is.null(github_url )) {
245
246
return (FALSE )
246
247
}
@@ -269,21 +270,23 @@ check_no_origin <- function() {
269
270
}
270
271
271
272
check_no_github_repo <- function (owner , repo , host ) {
273
+ spec <- glue(" {owner}/{repo}" )
272
274
repo_found <- tryCatch(
273
275
{
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
280
284
},
281
285
" http_error_404" = function (err ) FALSE
282
286
)
283
287
if (! repo_found ) {
284
288
return (invisible ())
285
289
}
286
- spec <- glue(" {owner}/{repo}" )
287
290
empirical_host <- parse_github_remotes(repo_info $ html_url )$ host
288
291
ui_abort(" Repo {.val {spec}} already exists on {.val {empirical_host}}." )
289
292
}
0 commit comments