git_init()creates a new repositorygit_find()to discover an existing local repository.git_info()shows basic information about a repository, such as the SHA and branch of the current HEAD.
Arguments
- path
the location of the git repository, see details.
- bare
if true, a Git repository without a working directory is created
- repo
The path to the git repository. If the directory is not a repository, parent directories are considered (see
git_find()). To disable this search, provide the filepath protected withI(). When using this parameter, always explicitly call by name (i.e.repo =) because future versions of gert may have additional parameters.
Value
git_find()andgit_init(): the path to the Git repository.git_info(): A list of information of the Git repository.
Details
For git_init() the path parameter sets the directory of the git repository
to create. If this directory already exists, it must be empty. If it does
not exist, it is created, along with any intermediate directories that don't
yet exist.
For git_find(), the path parameter specifies the directory at
which to start the search for a git repository. If it is not a git repository
itself, then its parent directory is consulted, then the parent's parent, and
so on.
Examples
# directory does not yet exist
r <- tempfile(pattern = "gert")
git_init(r)
git_find(r)
#> [1] "/tmp/RtmpcToVO2/gert6e424f9269b"
git_info(r)
#> $path
#> [1] "/tmp/RtmpcToVO2/gert6e424f9269b/"
#>
#> $bare
#> [1] FALSE
#>
#> $head
#> [1] NA
#>
#> $shorthand
#> [1] NA
#>
#> $commit
#> [1] NA
#>
#> $remote
#> [1] NA
#>
#> $upstream
#> [1] NA
#>
#> $reflist
#> character(0)
#>
# create a child directory, then a grandchild, then search
r_grandchild_dir <- file.path(r, "aaa", "bbb")
dir.create(r_grandchild_dir, recursive = TRUE)
git_find(r_grandchild_dir)
#> [1] "/tmp/RtmpcToVO2/gert6e424f9269b"
# cleanup
unlink(r, recursive = TRUE)
# directory exists but is empty
r <- tempfile(pattern = "gert")
dir.create(r)
git_init(r)
git_find(r)
#> [1] "/tmp/RtmpcToVO2/gert6e45fd26cc5"
# cleanup
unlink(r, recursive = TRUE)
