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) > source("util/check.R") > > ## 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) > config(repo, user.name = "Alice", user.email = "alice@example.org") > > ## Status case 1 > status_exp_1 <- structure(list(staged = empty_named_list(), + unstaged = empty_named_list(), + untracked = empty_named_list()), + class = "git_status") > status_obs_1 <- status(repo) > stopifnot(identical(print(status_obs_1), status_obs_1)) working directory clean > str(status_exp_1) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked: Named list() - attr(*, "class")= chr "git_status" > str(status_obs_1) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked: Named list() - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_1, status_exp_1)) > stopifnot(identical(capture.output(status(repo)), + "working directory clean")) > > ## Status case 2, include ignored files > status_exp_2 <- structure(list(staged = empty_named_list(), + unstaged = empty_named_list(), + untracked = empty_named_list(), + ignored = empty_named_list()), + class = "git_status") > status_obs_2 <- status(repo, ignored = TRUE) > status_obs_2 working directory clean > str(status_exp_2) List of 4 $ staged : Named list() $ unstaged : Named list() $ untracked: Named list() $ ignored : Named list() - attr(*, "class")= chr "git_status" > str(status_obs_2) List of 4 $ staged : Named list() $ unstaged : Named list() $ untracked: Named list() $ ignored : Named list() - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_2, status_exp_2)) > stopifnot(identical(capture.output(status(repo, ignored = TRUE)), + "working directory clean")) > > ## Create 4 files > writeLines("File-1", file.path(path, "test-1.txt")) > writeLines("File-2", file.path(path, "test-2.txt")) > writeLines("File-3", file.path(path, "test-3.txt")) > writeLines("File-4", file.path(path, "test-4.txt")) > > ## Status case 3: 4 untracked files > status_exp_3 <- structure(list(staged = empty_named_list(), + unstaged = empty_named_list(), + untracked = list(untracked = "test-1.txt", + untracked = "test-2.txt", + untracked = "test-3.txt", + untracked = "test-4.txt")), + class = "git_status") > status_obs_3 <- status(repo) > status_obs_3 Untracked files: Untracked: test-1.txt Untracked: test-2.txt Untracked: test-3.txt Untracked: test-4.txt > str(status_exp_3) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked:List of 4 ..$ untracked: chr "test-1.txt" ..$ untracked: chr "test-2.txt" ..$ untracked: chr "test-3.txt" ..$ untracked: chr "test-4.txt" - attr(*, "class")= chr "git_status" > str(status_obs_3) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked:List of 4 ..$ untracked: chr "test-1.txt" ..$ untracked: chr "test-2.txt" ..$ untracked: chr "test-3.txt" ..$ untracked: chr "test-4.txt" - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_3, status_exp_3)) > > ## Add file 1 and 2 to the repository and commit > add(repo, c("test-1.txt", "test-2.txt")) > commit(repo, "Commit message") [21e0afc] 2023-11-26: Commit message > > ## Status case 4: 2 untracked files > status_exp_4 <- structure(list(staged = empty_named_list(), + unstaged = empty_named_list(), + untracked = list(untracked = "test-3.txt", + untracked = "test-4.txt")), + class = "git_status") > status_obs_4 <- status(repo) > status_obs_4 Untracked files: Untracked: test-3.txt Untracked: test-4.txt > str(status_exp_4) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked:List of 2 ..$ untracked: chr "test-3.txt" ..$ untracked: chr "test-4.txt" - attr(*, "class")= chr "git_status" > str(status_obs_4) List of 3 $ staged : Named list() $ unstaged : Named list() $ untracked:List of 2 ..$ untracked: chr "test-3.txt" ..$ untracked: chr "test-4.txt" - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_4, status_exp_4)) > > ## Update file 1 & 2 > writeLines(c("File-1", "Hello world"), file.path(path, "test-1.txt")) > writeLines(c("File-2", "Hello world"), file.path(path, "test-2.txt")) > > ## Add file 1 > add(repo, "test-1.txt") > > ## Status case 5: 1 staged file, 1 unstaged file and 2 untracked files > status_exp_5 <- structure(list(staged = list(modified = "test-1.txt"), + unstaged = list(modified = "test-2.txt"), + untracked = list(untracked = "test-3.txt", + untracked = "test-4.txt")), + class = "git_status") > status_obs_5 <- status(repo) > status_obs_5 Untracked files: Untracked: test-3.txt Untracked: test-4.txt Unstaged changes: Modified: test-2.txt Staged changes: Modified: test-1.txt > str(status_exp_5) List of 3 $ staged :List of 1 ..$ modified: chr "test-1.txt" $ unstaged :List of 1 ..$ modified: chr "test-2.txt" $ untracked:List of 2 ..$ untracked: chr "test-3.txt" ..$ untracked: chr "test-4.txt" - attr(*, "class")= chr "git_status" > str(status_obs_5) List of 3 $ staged :List of 1 ..$ modified: chr "test-1.txt" $ unstaged :List of 1 ..$ modified: chr "test-2.txt" $ untracked:List of 2 ..$ untracked: chr "test-3.txt" ..$ untracked: chr "test-4.txt" - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_5, status_exp_5)) > > ## Add .gitignore file with file test-4.txt > writeLines("test-4.txt", file.path(path, ".gitignore")) > > ## Status case 6: 1 staged file, 1 unstaged file, 2 untracked files > ## and 1 ignored file > status_exp_6 <- structure(list(staged = list(modified = "test-1.txt"), + unstaged = list(modified = "test-2.txt"), + untracked = list(untracked = ".gitignore", + untracked = "test-3.txt"), + ignored = list(ignored = "test-4.txt")), + class = "git_status") > status_obs_6 <- status(repo, ignore = TRUE) > status_obs_6 Ignored files: Ignored: test-4.txt Untracked files: Untracked: .gitignore Untracked: test-3.txt Unstaged changes: Modified: test-2.txt Staged changes: Modified: test-1.txt > str(status_exp_6) List of 4 $ staged :List of 1 ..$ modified: chr "test-1.txt" $ unstaged :List of 1 ..$ modified: chr "test-2.txt" $ untracked:List of 2 ..$ untracked: chr ".gitignore" ..$ untracked: chr "test-3.txt" $ ignored :List of 1 ..$ ignored: chr "test-4.txt" - attr(*, "class")= chr "git_status" > str(status_obs_6) List of 4 $ staged :List of 1 ..$ modified: chr "test-1.txt" $ unstaged :List of 1 ..$ modified: chr "test-2.txt" $ untracked:List of 2 ..$ untracked: chr ".gitignore" ..$ untracked: chr "test-3.txt" $ ignored :List of 1 ..$ ignored: chr "test-4.txt" - attr(*, "class")= chr "git_status" > stopifnot(identical(status_obs_6, status_exp_6)) > > ## Cleanup > unlink(path, recursive = TRUE) > > proc.time() user system elapsed 0.26 0.06 0.26