Print or return a detailed git log
of the git repository located in the specified directory.
Source: R/general_git_log.R
git_log.Rd
This function checks if the specified directory is a Git repository and, if
so, executes a git log
command to either print the log to the console or
return it. It supports execution on Windows and Linux operating systems and
provides a visually appealing graph format of the log, showing the commit
hash, references, commit message, relative commit date, and author name.
Arguments
- path
Character. Path to the directory to check. Defaults to the current working directory ".". If the path does not exist, the function will stop and throw an error. If the path is not a git repository, the function will throw a warning.
- n_commits
Integer. Number of recent commits to display. If
NULL
(the default), the complete log is shown. Ifn_commits
is notNULL
or a positive number, the function will stop and throw an error. This parameter is ignored ifreturn_log
isTRUE
.- return_log
Logical. Whether to return the log (
TRUE
) or print it to the console (FALSE
, default). IfTRUE
, the function returns a character vector containing the log lines.
Value
If return_log
is TRUE
, returns a character vector containing the
git log lines. If return_log
is FALSE
, the function is called for its
side effect of printing to the console.
Note
The function will stop and throw an error if the specified path does
not exist, the operating system is not supported, the directory is not a
Git repository, Git is not installed, or if the n_commits
parameter is
not NULL
or a positive number.
Examples
# Show the most recent commit
git_log(n_commits = 1)
#> * fa6b5ae - (grafted, HEAD -> main, origin/main, origin/HEAD) CV model postprocessing + fix typo in convergence plots and add a function to plot range values of beta params + merge cpp functions into single md file (3 minutes ago) <Ahmed El-Gabbas>
# Show the most recent 5 commits
git_log(n_commits = 5)
#> * fa6b5ae - (grafted, HEAD -> main, origin/main, origin/HEAD) CV model postprocessing + fix typo in convergence plots and add a function to plot range values of beta params + merge cpp functions into single md file (3 minutes ago) <Ahmed El-Gabbas>
# Return the log as a character vector
Log <- git_log(return_log = TRUE)
length(Log)
#> [1] 1
head(Log, 8)
#> [1] "* fa6b5ae - (grafted, HEAD -> main, origin/main, origin/HEAD) CV model postprocessing + fix typo in convergence plots and add a function to plot range values of beta params + merge cpp functions into single md file (3 minutes ago) <Ahmed El-Gabbas>"
if (FALSE) { # \dontrun{
# not a git repo
git_log(path = "C:/")
# #> Error: The provided path does not exist.
} # }