Skip to content

Commit

Permalink
Add 'index_remove_bypath'. Closes #250
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
  • Loading branch information
stewid committed Aug 7, 2016
1 parent 7b0f435 commit 1813028
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -72,6 +72,7 @@ exportMethods(hash)
exportMethods(hashfile)
exportMethods(head)
exportMethods(in_repository)
exportMethods(index_remove_bypath)
exportMethods(init)
exportMethods(is_bare)
exportMethods(is_binary)
Expand Down
62 changes: 61 additions & 1 deletion R/index.r
@@ -1,5 +1,5 @@
## git2r, R bindings to the libgit2 library.
## Copyright (C) 2013-2015 The git2r contributors
## Copyright (C) 2013-2016 The git2r contributors
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License, version 2,
Expand Down Expand Up @@ -226,3 +226,63 @@ setMethod("rm_file",
invisible(NULL)
}
)

##' Remove an index entry corresponding to a file on disk
##'
##' @rdname index_remove_bypath-methods
##' @docType methods
##' @param repo The repository \code{object}.
##' @param path character vector with filenames to remove. The path
##' must be relative to the repository's working folder. It may
##' exist. If this file currently is the result of a merge
##' conflict, this file will no longer be marked as
##' conflicting. The data about the conflict will be moved to the
##' "resolve undo" (REUC) section.
##' @return invisible(NULL)
##' @keywords methods
##' @include S4_classes.r
##' @examples
##' \dontrun{
##' ## Initialize a repository
##' path <- tempfile(pattern="git2r-")
##' dir.create(path)
##' repo <- init(path)
##'
##' ## Create a user
##' config(repo, user.name="Alice", user.email="alice@@example.org")
##'
##' ## Create a file
##' writeLines("Hello world!", file.path(path, "file-to-remove.txt"))
##'
##' ## Add file to repository
##' add(repo, "file-to-remove.txt")
##'
##' ## View status of repository
##' status(repo)
##'
##' ## Remove file
##' index_remove_bypath(repo, "file-to-remove.txt")
##'
##' ## View status of repository
##' status(repo)
##' }
##'
setGeneric("index_remove_bypath",
signature = c("repo", "path"),
function(repo, path)
standardGeneric("index_remove_bypath"))

##' @rdname index_remove_bypath-methods
##' @export
setMethod("index_remove_bypath",
signature(repo = "git_repository",
path = "character"),
function(repo, path)
{
if (length(path)) {
.Call(git2r_index_remove_bypath, repo, path)
}

invisible(NULL)
}
)
57 changes: 57 additions & 0 deletions man/index_remove_bypath-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion tests/index.R
@@ -1,5 +1,5 @@
## git2r, R bindings to the libgit2 library.
## Copyright (C) 2013-2015 The git2r contributors
## Copyright (C) 2013-2016 The git2r contributors
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License, version 2,
Expand Down Expand Up @@ -38,6 +38,32 @@ writeLines("Hello world!", file.path(path, "sub-folder", "file-3.txt"))
writeLines("Hello world!", file.path(path, "sub-folder", "sub-sub-folder", "file-4.txt"))
writeLines("Hello world!", file.path(path, "sub-folder", "sub-sub-folder", "file-5.txt"))

## Add
add(repo, "file-1.txt")
status_exp <- structure(list(staged = structure(list(new = "file-1.txt"),
.Names = "new"),
unstaged = structure(list(),
.Names = character(0)),
untracked = structure(list(untracked = "sub-folder/"),
.Names = "untracked")),
.Names = c("staged", "unstaged", "untracked"),
class = "git_status")
status_obs <- status(repo)
stopifnot(identical(status_obs, status_exp))

## Index remove by path
index_remove_bypath(repo, "file-1.txt")
status_exp <- structure(list(staged = structure(list(), .Names = character(0)),
unstaged = structure(list(), .Names = character(0)),
untracked = structure(list(
untracked = "file-1.txt",
untracked = "sub-folder/"),
.Names = c("untracked", "untracked"))),
.Names = c("staged", "unstaged", "untracked"),
class = "git_status")
status_obs <- status(repo)
stopifnot(identical(status_obs, status_exp))

## Add
add(repo, "sub-folder")
status_exp <- structure(list(staged = structure(list(
Expand Down

0 comments on commit 1813028

Please sign in to comment.