R Under development (unstable) (2023-11-25 r85635 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## git2r, R bindings to the libgit2 library. > ## Copyright (C) 2013-2023 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. > > library(git2r) > > ## For debugging > sessionInfo() R Under development (unstable) (2023-11-25 r85635 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: [1] LC_COLLATE=C LC_CTYPE=German_Germany.utf8 [3] LC_MONETARY=C LC_NUMERIC=C [5] LC_TIME=C time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] git2r_0.33.0 loaded via a namespace (and not attached): [1] compiler_4.4.0 > libgit2_version() $major [1] 1 $minor [1] 7 $rev [1] 1 > libgit2_features() $threads [1] TRUE $https [1] TRUE $ssh [1] FALSE > > > ## Create a directory in tempdir > path <- tempfile(pattern = "git2r-") > dir.create(path) > > ## Initialize a repository > repo <- init(path, branch = "main") > config(repo, user.name = "Alice", user.email = "alice@example.org") > > ## Create first commit > writeLines("Hello world!", file.path(path, "test.txt")) > add(repo, "test.txt") > commit_1 <- commit(repo, "First commit message") > > ## Edit file and checkout > writeLines(c("Hello world!", "Hello world!"), file.path(path, "test.txt")) > status_exp_1 <- structure(list(staged = structure(list(), + .Names = character(0)), + unstaged = structure(list(modified = "test.txt"), + .Names = "modified"), + untracked = structure(list(), + .Names = character(0))), + .Names = c("staged", "unstaged", "untracked"), + class = "git_status") > status_obs_1 <- status(repo) > str(status_exp_1) List of 3 $ staged : Named list() $ unstaged :List of 1 ..$ modified: chr "test.txt" $ untracked: Named list() - attr(*, "class")= chr "git_status" > str(status_obs_1) List of 3 $ staged : Named list() $ unstaged :List of 1 ..$ modified: chr "test.txt" $ untracked: Named list() - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_1, status_exp_1)) > checkout(repo, path = "test.txt") > status_exp_2 <- structure(list(staged = structure(list(), + .Names = character(0)), + unstaged = structure(list(), + .Names = character(0)), + untracked = structure(list(), + .Names = character(0))), + .Names = c("staged", "unstaged", "untracked"), + class = "git_status") > status_obs_2 <- status(repo) > str(status_exp_2) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked: Named list() - attr(*, "class")= chr "git_status" > str(status_obs_2) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked: Named list() - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_2, status_exp_2)) > > ## Create second commit > writeLines(c("Hello world!", "HELLO WORLD!"), file.path(path, "test.txt")) > add(repo, "test.txt") > commit_2 <- commit(repo, "Second commit message") > tag(repo, "commit_2", "Tag message") > > ## Create third commit > writeLines(c("Hello world!", "HELLO WORLD!", "HeLlO wOrLd!"), + file.path(path, "test.txt")) > add(repo, "test.txt") > commit_3 <- commit(repo, "Third commit message") > > ## Check HEAD > stopifnot(identical(is_detached(repo), FALSE)) > stopifnot(identical(repository_head(repo)$name, "main")) > > ## Check show and summary > repo Local: main D:/temp/RtmpQNXgzW/git2r-23b0024442642 Head: [a78b087] 2023-11-26: Third commit message > summary(repo) Local: main D:/temp/RtmpQNXgzW/git2r-23b0024442642 Head: [a78b087] 2023-11-26: Third commit message Branches: 1 Tags: 1 Commits: 3 Contributors: 1 Stashes: 0 Ignored files: 0 Untracked files: 0 Unstaged files: 0 Staged files: 0 Latest commits: [a78b087] 2023-11-26: Third commit message [211f7df] 2023-11-26: Second commit message [317c11b] 2023-11-26: First commit message > > ## Checkout first commit > checkout(commit_1, TRUE) > stopifnot(identical(is_detached(repo), TRUE)) > stopifnot(identical(repository_head(repo), commit_1)) > stopifnot(identical(readLines(file.path(path, "test.txt")), "Hello world!")) > > ## Check show and summary > repo Local: (detached) D:/temp/RtmpQNXgzW/git2r-23b0024442642 Head: [317c11b] 2023-11-26: First commit message > summary(repo) Local: (detached) D:/temp/RtmpQNXgzW/git2r-23b0024442642 Head: [317c11b] 2023-11-26: First commit message Branches: 1 Tags: 1 Commits: 1 Contributors: 1 Stashes: 0 Ignored files: 0 Untracked files: 0 Unstaged files: 0 Staged files: 0 Latest commits: [317c11b] 2023-11-26: First commit message > > ## Checkout tag > checkout(tags(repo)[[1]], TRUE) > stopifnot(identical(is_detached(repo), TRUE)) > stopifnot(identical(readLines(file.path(path, "test.txt")), + c("Hello world!", "HELLO WORLD!"))) > > ## Check is_detached with missing repo argument > wd <- setwd(path) > stopifnot(identical(is_detached(), TRUE)) > if (!is.null(wd)) + setwd(wd) > > ## Cleanup > unlink(path, recursive = TRUE) > > proc.time() user system elapsed 0.20 0.09 0.29