-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,621 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
^\.Rproj\.user$ | ||
^windows | ||
^.*\.a$ | ||
^man-roxygen$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#' Open a git connection | ||
#' @name git_connection | ||
#' @rdname git_connection-class | ||
#' @param repo.path The path of the root of the repository | ||
#' @param local.path A path within the repository | ||
#' @param key Optional: the path to a private ssh key. The public key is assumed | ||
#' to have the same path with a '.pub' extension. Using in case of ssh | ||
#' authentication. | ||
#' @param username The optional username used in case of https authentication. | ||
#' Ignored when \code{key} is provided. | ||
#' @param password The password required for the ssh key or the username. Should | ||
#' be missing when the ssh-key doesn't require a password. | ||
#' @param commit.user the name of the user how will commit | ||
#' @param commit.email the email of the user how will commit | ||
#' @export | ||
#' @importFrom methods new | ||
#' @importFrom assertthat assert_that is.string | ||
#' @include S4_classes.r | ||
#' @template thierry | ||
git_connection <- function( | ||
repo.path, | ||
local.path = ".", | ||
key, | ||
username, | ||
password, | ||
commit.user, | ||
commit.email | ||
){ | ||
assert_that(is.string(local.path)) | ||
assert_that(is.string(commit.user)) | ||
assert_that(is.string(commit.email)) | ||
assert_that( | ||
is.git(path = repo.path), | ||
msg = paste(repo.path, "is not a git repo") | ||
) | ||
repo <- repository(repo.path) | ||
config(repo, user.name = commit.user, user.email = commit.email) | ||
assert_that( | ||
dir.exists(paste(repo.path, local.path, sep = "/")), | ||
msg = paste(local.path, "is not a directory") | ||
) | ||
|
||
if (missing(key) & missing(username)) { | ||
return( | ||
new( | ||
"git_connection", | ||
Repository = repo, | ||
LocalPath = local.path, | ||
Credentials = NULL, | ||
CommitUser = commit.user, | ||
CommitEmail = commit.email | ||
) | ||
) | ||
} | ||
|
||
if (missing(username)) { | ||
assert_that(is.string(key)) | ||
|
||
if (missing(password)) { | ||
return( | ||
new( | ||
"git_connection", | ||
Repository = repo, | ||
LocalPath = local.path, | ||
Credentials = cred_ssh_key( | ||
publickey = paste0(key, ".pub"), | ||
privatekey = key | ||
), | ||
CommitUser = commit.user, | ||
CommitEmail = commit.email | ||
) | ||
) | ||
} | ||
|
||
assert_that(is.string(password)) | ||
return( | ||
new( | ||
"git_connection", | ||
Repository = repo, | ||
LocalPath = local.path, | ||
Credentials = cred_ssh_key( | ||
publickey = paste0(key, ".pub"), | ||
privatekey = key, | ||
passphrase = password | ||
), | ||
CommitUser = commit.user, | ||
CommitEmail = commit.email | ||
) | ||
) | ||
} | ||
|
||
assert_that(is.string(username)) | ||
assert_that(username != "") | ||
assert_that(is.string(password)) | ||
assert_that(password != "") | ||
return( | ||
new( | ||
"git_connection", | ||
Repository = repo, | ||
LocalPath = local.path, | ||
Credentials = cred_user_pass( | ||
username = username, | ||
password = password | ||
), | ||
CommitUser = commit.user, | ||
CommitEmail = commit.email | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#' Get the info from the latest commit of a file | ||
#' @inheritParams read_delim_git | ||
#' @name git_recent | ||
#' @rdname git_recent | ||
#' @exportMethod git_recent | ||
#' @docType methods | ||
#' @importFrom methods setGeneric | ||
#' @include git_connection.r | ||
#' @template thierry | ||
setGeneric( | ||
name = "git_recent", | ||
def = function(file, connection, ...){ | ||
standard.generic("git_recent") | ||
} | ||
) | ||
|
||
#' @rdname git_recent | ||
#' @aliases git_recent,git_connection-methods | ||
#' @importFrom methods setMethod | ||
setMethod( | ||
f = "git_recent", | ||
signature = signature(connection = "ANY"), | ||
definition = function(file, connection, ...){ | ||
this.connection <- git_connection(repo.path = connection, ...) | ||
git_recent(file = file, connection = this.connection) | ||
} | ||
) | ||
|
||
#' @rdname git_recent | ||
#' @aliases git_recent,git_connection-methods | ||
#' @importFrom methods setMethod | ||
#' @importFrom assertthat assert_that is.string | ||
setMethod( | ||
f = "git_recent", | ||
signature = signature(connection = "git_connection"), | ||
definition = function(file, connection, ...){ | ||
assert_that(is.string(file)) | ||
|
||
if (is.null(head(connection@Repository))) { | ||
stop("no commits in current branch") | ||
} | ||
|
||
old.wd <- getwd() | ||
setwd(connection@Repository@path) | ||
commit.info <- system( | ||
paste0( | ||
"git log -n 1 --date=iso ", | ||
connection@LocalPath, "/", file | ||
), | ||
intern = TRUE | ||
) | ||
setwd(old.wd) | ||
date <- commit.info[grep("^Date:", commit.info)] | ||
date <- as.POSIXct(date, format = "Date: %F %T %z") | ||
commit <- commit.info[grep("^commit", commit.info)] | ||
commit <- gsub("^commit ", "", commit) | ||
author <- commit.info[grep("^Author:", commit.info)] | ||
author <- gsub("^Author: ", "", author) | ||
return(list( | ||
Commit = commit, | ||
Author = author, | ||
Date = date | ||
)) | ||
} | ||
) |
Oops, something went wrong.