Skip to content

Commit

Permalink
New (roundabout) approach to creating gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Aug 25, 2021
1 parent 0281a15 commit 5256ee8
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions R/github-pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,32 @@ create_gh_pages_branch <- function(tr, branch = "gh-pages") {
Initializing empty, orphan {ui_value(branch)} branch in GitHub repo \\
{ui_value(tr$repo_spec)}")

# git hash-object -t tree /dev/null
sha_empty_tree <- "4b825dc642cb6eb9a060e54bf8d69288fbee4904"

# Create commit with empty tree
res <- gh(
# GitHub no longer allows you to directly create an empty tree
# hence this roundabout method of getting an orphan branch with no files
tree <- gh(
"POST /repos/{owner}/{repo}/git/trees",
tree = list(list(
path = "_temp_file_ok_to_delete",
mode = "100644",
type = "blob",
content = ""
))
)
commit <- gh(
"POST /repos/{owner}/{repo}/git/commits",
message = "first commit",
tree = sha_empty_tree
message = "Init orphan branch",
tree = tree$sha
)

# Assign ref to above commit
gh(
ref <- gh(
"POST /repos/{owner}/{repo}/git/refs",
ref = "refs/heads/gh-pages",
sha = res$sha
ref = glue("refs/heads/{branch}"),
sha = commit$sha
)
gh(
"DELETE /repos/{owner}/{repo}/contents/_temp_file_ok_to_delete",
message = "Remove temp file",
sha = purrr::pluck(tree, "tree", 1, "sha"),
branch = branch
)

TRUE
Expand Down

0 comments on commit 5256ee8

Please sign in to comment.