File: tag.R

package info (click to toggle)
r-cran-git2r 0.26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 6,884 kB
  • sloc: ansic: 101,730; sh: 3,364; makefile: 2
file content (215 lines) | stat: -rw-r--r-- 6,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
## git2r, R bindings to the libgit2 library.
## Copyright (C) 2013-2019 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,
## as published by the Free Software Foundation.
##
## git2r is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

##' Create tag targeting HEAD commit in repository
##'
##' @param object The repository \code{object}.
##' @param name Name for the tag.
##' @param message The tag message. Specify a tag message to create an
##'     annotated tag. A lightweight tag is created if the message
##'     parameter is \code{NULL}.
##' @param session Add sessionInfo to tag message. Default is FALSE.
##' @param tagger The tagger (author) of the tag
##' @param force Overwrite existing tag. Default = FALSE
##' @return invisible(\code{git_tag}) object
##' @export
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
##' path <- tempfile(pattern="git2r-")
##' dir.create(path)
##' repo <- init(path)
##'
##' ## Create a user
##' config(repo, user.name="Alice", user.email="alice@@example.org")
##'
##' ## Commit a text file
##' filename <- file.path(path, "example.txt")
##' writeLines("Hello world!", filename)
##' add(repo, "example.txt")
##' commit(repo, "First commit message")
##'
##' ## Create an annotated tag
##' tag(repo, "v1.0", "Tag message")
##'
##' ## List tags
##' tags(repo)
##'
##' ## Make a change to the text file and commit.
##' writeLines(c("Hello world!", "HELLO WORLD!"), filename)
##' add(repo, "example.txt")
##' commit(repo, "Second commit message")
##'
##' ## Create a lightweight tag
##' tag(repo, "v2.0")
##'
##' ## List tags
##' tags(repo)
##' }
tag <- function(object = ".",
                name    = NULL,
                message = NULL,
                session = FALSE,
                tagger  = NULL,
                force   = FALSE)
{
    object <- lookup_repository(object)

    if (isTRUE(session))
        message <- add_session_info(message)

    if (is.null(tagger))
        tagger <- default_signature(object)

    invisible(.Call(git2r_tag_create, object, name, message, tagger, force))
}

##' Check if object is a git_tag object
##'
##' @param object Check if object is a git_tag object
##' @return TRUE if object is a git_tag, else FALSE
##' @export
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
##' path <- tempfile(pattern="git2r-")
##' dir.create(path)
##' repo <- init(path)
##'
##' ## Create a user
##' config(repo, user.name="Alice", user.email="alice@@example.org")
##'
##' ## Commit a text file
##' writeLines("Hello world!", file.path(path, "example.txt"))
##' add(repo, "example.txt")
##' commit(repo, "First commit message")
##'
##' ## Create tag
##' tag(repo, "Tagname", "Tag message")
##'
##' is_tag(tags(repo)[[1]])
##' is_tag(last_commit(repo))
##' }
is_tag <- function(object) {
    inherits(object, "git_tag")
}

##' Delete an existing tag reference
##'
##' @param object Can be either the path (default is ".") to a
##'     repository, or a \code{git_repository} object, or a
##'     \code{git_tag} object. or the tag name.
##' @param name If the \code{object} argument is a path to a
##'     repository or a \code{git_repository}, the name of the tag to
##'     delete.
##' @return \code{invisible(NULL)}
##' @export
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
##' path <- tempfile(pattern="git2r-")
##' dir.create(path)
##' repo <- init(path)
##'
##' ## Create a user
##' config(repo, user.name="Alice", user.email="alice@@example.org")
##'
##' ## Commit a text file
##' writeLines("Hello world!", file.path(path, "example.txt"))
##' add(repo, "example.txt")
##' commit(repo, "First commit message")
##'
##' ## Create two tags
##' tag(repo, "Tag1", "Tag message 1")
##' t2 <- tag(repo, "Tag2", "Tag message 2")
##'
##' ## List the two tags in the repository
##' tags(repo)
##'
##' ## Delete the two tags in the repository
##' tag_delete(repo, "Tag1")
##' tag_delete(t2)
##'
##' ## Show the empty list with tags in the repository
##' tags(repo)
##' }
tag_delete <- function(object = ".", name = NULL) {
    if (is_tag(object)) {
        name <- object$name
        object <- object$repo
    } else {
        object <- lookup_repository(object)
    }

    .Call(git2r_tag_delete, object, name)
    invisible(NULL)
}

##' Tags
##'
##' @template repo-param
##' @return list of tags in repository
##' @export
##' @examples
##' \dontrun{
##' ## Initialize a temporary repository
##' path <- tempfile(pattern="git2r-")
##' dir.create(path)
##' repo <- init(path)
##'
##' ## Create a user
##' config(repo, user.name="Alice", user.email="alice@@example.org")
##'
##' ## Commit a text file
##' writeLines("Hello world!", file.path(path, "example.txt"))
##' add(repo, "example.txt")
##' commit(repo, "First commit message")
##'
##' ## Create tag
##' tag(repo, "Tagname", "Tag message")
##'
##' ## List tags
##' tags(repo)
##' }
tags <- function(repo = ".") {
    .Call(git2r_tag_list, lookup_repository(repo))
}

##' @export
format.git_tag <- function(x, ...) {
    sprintf("[%s] %s", substr(x$target, 1 , 6), x$name)
}

##' @export
print.git_tag <- function(x, ...) {
    cat(format(x, ...), "\n", sep = "")
    invisible(x)
}

##' @export
summary.git_tag <- function(object, ...) {
    cat(sprintf(paste0("name:    %s\n",
                       "target:  %s\n",
                       "tagger:  %s <%s>\n",
                       "when:    %s\n",
                       "message: %s\n"),
                object$name,
                object$target,
                object$tagger$name,
                object$tagger$email,
                as.character(object$tagger$when),
                object$message))
}