@@ -244,7 +244,7 @@ git_stat_files <- function(files, ref = "HEAD", max = NULL, repo = '.') {
244244# ' Applies the inverse of the changes introduced by a given commit, equivalent
245245# ' to `git revert <commit>`. The commit must be reachable from the current HEAD.
246246# '
247- # ' By default, a new revert commit is created immediately. Set `no_commit = TRUE `
247+ # ' By default, a new revert commit is created immediately. Set `commit = FALSE `
248248# ' to only stage the reverted changes without committing, leaving you free to
249249# ' amend or combine them before calling [git_commit()].
250250# '
@@ -253,11 +253,11 @@ git_stat_files <- function(files, ref = "HEAD", max = NULL, repo = '.') {
253253# ' @rdname git_revert
254254# ' @family git
255255# ' @inheritParams git_open
256- # ' @inheritParams git_commit
257256# ' @inheritParams git_commit_info
258- # ' @param no_commit if `TRUE `, stage the reverted changes without creating a
259- # ' commit. Default is `FALSE `, that is to say, by default a commit is made.
257+ # ' @param commit if `FALSE `, stage the reverted changes without creating a
258+ # ' commit. Default is `TRUE `, that is to say, by default a commit is made.
260259# ' @param message a commit message. Similar default to `git revert`.
260+ # ' @param ... other parameters passed to `git_commit`
261261# ' @return The SHA of the new revert commit (invisibly), or `NULL` when
262262# ' `no_commit = TRUE`.
263263# ' @examplesIf interactive()
@@ -300,23 +300,21 @@ git_stat_files <- function(files, ref = "HEAD", max = NULL, repo = '.') {
300300# ' @useDynLib gert R_git_revert
301301git_revert <- function (
302302 ref ,
303+ commit = TRUE ,
303304 message = NULL ,
304- author = NULL ,
305- committer = NULL ,
306- no_commit = FALSE ,
305+ ... ,
307306 repo = ' .'
308307) {
309308 repo <- git_open(repo )
310309 assert_string(ref )
311- stopifnot(is.logical(no_commit ), length(no_commit ) == 1 )
310+ stopifnot(is.logical(commit ), length(commit ) == 1 )
312311
313- sha <- try(git_commit_id(ref , repo = repo ), silent = TRUE )
314- if (inherits(sha , " try-error" )) {
312+ sha <- tryCatch(git_commit_id(ref , repo = repo ), error = function (e ){
315313 stop(sprintf(
316314 " Can't find reference/commit '%s' in the current branch history" ,
317315 ref
318316 ))
319- }
317+ })
320318
321319 head_sha <- git_commit_id(" HEAD" , repo = repo )
322320 sha_descends_from_head <- git_commit_descendant_of(
@@ -330,20 +328,12 @@ git_revert <- function(
330328
331329 .Call(R_git_revert , repo , sha )
332330
333- if (no_commit ) {
334- return (NULL )
335- }
336-
337- if (is.null(message )) {
338- message <- revert_message(sha , repo )
331+ if (isTRUE(commit )) {
332+ if (is.null(message )) {
333+ message <- revert_message(sha , repo )
334+ }
335+ git_commit(message , ... , repo = repo )
339336 }
340-
341- invisible (git_commit(
342- message ,
343- author = author ,
344- committer = committer ,
345- repo = repo
346- ))
347337}
348338
349339assert_string <- function (x ) {
0 commit comments