From 9cfdca75cd2bab533f80616a2386a4080879a0a5 Mon Sep 17 00:00:00 2001 From: John Blischak Date: Thu, 7 Nov 2019 12:36:51 -0500 Subject: [PATCH] Tests paths from a subdirectory of the Git repo. See #394. --- tests/subdirectory-absolute.R | 68 +++++++++++++++++++++++++++++++++++ tests/subdirectory-relative.R | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 tests/subdirectory-absolute.R create mode 100644 tests/subdirectory-relative.R diff --git a/tests/subdirectory-absolute.R b/tests/subdirectory-absolute.R new file mode 100644 index 000000000..0c1071ed5 --- /dev/null +++ b/tests/subdirectory-absolute.R @@ -0,0 +1,68 @@ +## git2r, R bindings to the libgit2 library. +## Copyright (C) 2013-2019 The git2r contributors +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License, version 2, +## as published by the Free Software Foundation. +## +## git2r is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License along +## with this program; if not, write to the Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +## Testing use of absolute paths when the working directory is a subdirectory + +library("git2r") + +## For debugging +sessionInfo() + +## Initialize a temporary repository +path <- tempfile(pattern = "git2r-") +dir.create(path) +dir.create(file.path(path, "subfolder")) +repo <- init(path) + +## Create a user +config(repo, user.name = "Alice", user.email = "alice@example.org") + +# Change working directory to subdirectory +cwd <- setwd(file.path(path, "subfolder")) + +## Create two files +root <- file.path(path, "root.txt") +sub <- file.path(path, "subfolder", "sub.txt") +writeLines("root file", root) +writeLines("sub file", sub) + +## Add and commit +add(repo, c(root, sub)) +commit(repo, "Add files") + +## Check commits +commits_root <- commits(repo, path = root) +stopifnot(length(commits_root) == 1) +commits_sub <- commits(repo, path = sub) +stopifnot(length(commits_sub) == 1) +stopifnot(identical(commits_root, commits_sub)) + +## Remove and commit +rm_file(repo, c(root, sub)) +commit(repo, "Remove files") + +## Check commits +commits_total <- commits(repo) +stopifnot(length(commits_total) == 2) +commits_root_rm <- commits(repo, path = root) +stopifnot(length(commits_root_rm) == 2) +commits_sub_rm <- commits(repo, path = sub) +stopifnot(length(commits_sub_rm) == 2) +stopifnot(identical(commits_root_rm, commits_sub_rm)) + +## Cleanup +setwd(cwd) +unlink(path, recursive = TRUE) diff --git a/tests/subdirectory-relative.R b/tests/subdirectory-relative.R new file mode 100644 index 000000000..89eb5d41f --- /dev/null +++ b/tests/subdirectory-relative.R @@ -0,0 +1,68 @@ +## git2r, R bindings to the libgit2 library. +## Copyright (C) 2013-2019 The git2r contributors +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License, version 2, +## as published by the Free Software Foundation. +## +## git2r is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License along +## with this program; if not, write to the Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +## Testing use of relative paths when the working directory is a subdirectory + +library("git2r") + +## For debugging +sessionInfo() + +## Initialize a temporary repository +path <- tempfile(pattern = "git2r-") +dir.create(path) +dir.create(file.path(path, "subfolder")) +repo <- init(path) + +## Create a user +config(repo, user.name = "Alice", user.email = "alice@example.org") + +# Change working directory to subdirectory +cwd <- setwd(file.path(path, "subfolder")) + +## Create two files +root <- "../root.txt" +sub <- "sub.txt" +writeLines("root file", root) +writeLines("sub file", sub) + +## Add and commit +add(repo, c(root, sub)) +commit(repo, "Add files") + +## Check commits +commits_root <- commits(repo, path = root) +stopifnot(length(commits_root) == 1) +commits_sub <- commits(repo, path = sub) +stopifnot(length(commits_sub) == 1) +stopifnot(identical(commits_root, commits_sub)) + +## Remove and commit +rm_file(repo, c(root, sub)) +commit(repo, "Remove files") + +## Check commits +commits_total <- commits(repo) +stopifnot(length(commits_total) == 2) +commits_root_rm <- commits(repo, path = root) +stopifnot(length(commits_root_rm) == 2) +commits_sub_rm <- commits(repo, path = sub) +stopifnot(length(commits_sub_rm) == 2) +stopifnot(identical(commits_root_rm, commits_sub_rm)) + +## Cleanup +setwd(cwd) +unlink(path, recursive = TRUE)