R/info-git.R

repo_is_git <- function (path) {

    path <- convert_path (path)

    g <- tryCatch (
        gert::git_find (path),
        error = function (e) e
    )

    return (!methods::is (g, "libgit2_error"))
}

#' Return the $git item of main pkgcheck return result
#'
#' Note the prefix is `pkgcheck`, not `pkgchk_`: This is not a check, just a
#' function to return summary data.
#' @noRd
pkginfo_git_info <- function (path) {

    path <- convert_path (path)

    u <- pkginfo_url_from_desc (path)

    branch_default <- branch <- NULL
    if (repo_is_git (path)) {
        branch <- gert::git_branch (path)
    }

    if (length (u) > 0L) {

        repo <- utils::tail (strsplit (u, "/") [[1]], 1)
        org <- utils::tail (strsplit (u, "/") [[1]], 2) [1]
        if (has_gh_access ()) {
            branch_default <- get_default_github_branch (org, repo)
        }
    }

    ret <- list ()

    if (repo_is_git (path)) {

        gitlog <- gert::git_log (repo = path, max = 1e6)

        # use email addresses to identify unique authors
        auts <- gsub ("^.*<|>$", "", unique (gitlog$author))

        ret <- list (
            HEAD = gitlog$commit [1],
            branch = branch,
            branch_default = branch_default,
            num_commits = nrow (gitlog),
            since = min (gitlog$time),
            num_authors = length (unique (auts))
        )
    }

    return (ret)
}

Try the pkgcheck package in your browser

Any scripts or data that you put into this service are public.

pkgcheck documentation built on Oct. 13, 2026, 5:06 p.m.