Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting working dir correctly for git2r commits #70

Merged
merged 4 commits into from Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/insertPackage.R
Expand Up @@ -96,7 +96,7 @@ insertPackage <- function(file,
pkgtype <- identifyPackageType(file)
reldir <- getPathForPackage(file)

pkgdir <- file.path(repodir, reldir)
pkgdir <- normalizePath(file.path(repodir, reldir))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part is fine.


if (!file.exists(pkgdir)) {
## TODO: this could be in a git branch, need checking
Expand All @@ -117,10 +117,10 @@ insertPackage <- function(file,
if (haspkg) {
repo <- git2r::repository(repodir)
setwd(pkgdir)
git2r::add(repo, file.path(reldir, pkg))
git2r::add(repo, file.path(reldir, "PACKAGES"))
git2r::add(repo, file.path(reldir, "PACKAGES.gz"))
git2r::add(repo, file.path(reldir, "PACKAGES.rds"))
git2r::add(repo, pkg)
git2r::add(repo, "PACKAGES")
git2r::add(repo, "PACKAGES.gz")
git2r::add(repo, "PACKAGES.rds")
tryCatch(git2r::commit(repo, msg), error = function(e) warning(e))
#TODO: authentication woes? git2r::push(repo)
message("Added and committed ", pkg, " plus PACKAGES files. Still need to push.\n")
Expand Down
42 changes: 42 additions & 0 deletions tests/skeleton_git2r.R
@@ -0,0 +1,42 @@

testSkeletonGit2r <- function() {
if(!requireNamespace("git2r")) return(warning("couldn't find git2r"))

wd <- tempdir()

# options(error=traceback)

# make a package to test with
.foofn <- function() "foo"
utils::package.skeleton(name = "foo", list=".foofn", environment = environment(), path=wd)
print(dir(wd, recursive = TRUE))

message("building")

#https://github.com/r-lib/testthat/issues/129
R_TESTS=Sys.getenv("R_TESTS")
Sys.setenv(R_TESTS="")
cwd <- getwd()
setwd(wd)
system("R CMD build foo --no-manual")
setwd(cwd)
Sys.setenv(R_TESTS=R_TESTS)
message("dratting")

# make a repo to test with
rdir <- file.path(wd, "drat")

dir.create(rdir)
repo <- git2r::init(rdir)
git2r::config(repo, user.name="Alice", user.email="alice@example.org")
cat("foo", file=file.path(rdir, "README"))
git2r::add(repo, "README")
comm <- git2r::commit(repo, "init")
git2r::branch_create(comm,"gh-pages")

# finally add the package
drat::insertPackage(file = file.path(wd, "foo_1.0.tar.gz"), repodir = rdir, commit = "test")
list(git2r::status(repo), dir(rdir, recursive = TRUE))
}

testSkeletonGit2r()