Skip to content

Commit 08698af

Browse files
mattyclarksonJohn Haley
authored andcommitted
Added Repository.createTag API
This allows a user to easily create an annotated tag in a repository: ``` repository.createTag(oid, '0.0.0', 'version 0.0.0') .then(function(tag) { // The new tag is returned }); ```
1 parent f2ef49c commit 08698af

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/repository.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,30 @@ Repository.prototype.getTree = function(oid, callback) {
268268
}, callback);
269269
};
270270

271+
/**
272+
* Creates a new annotated tag
273+
*
274+
* @async
275+
* @param {String|Oid} String sha or Oid
276+
* @param {String} name the name of the tag
277+
* @param {String} message the description that will be attached to the
278+
* annotated tag
279+
* @return {Tag}
280+
*/
281+
Repository.prototype.createTag = function(oid, name, message, callback) {
282+
var repository = this;
283+
var signature = repository.defaultSignature();
284+
285+
return Commit.lookup(repository, oid)
286+
.then(function(commit) {
287+
// Final argument is `force` which overwrites any previous tag
288+
return Tag.create(repository, name, commit, signature, message, 0);
289+
})
290+
.then(function(tagOid) {
291+
return repository.getTag(tagOid, callback);
292+
});
293+
};
294+
271295
/**
272296
* Retrieve the tag represented by the oid.
273297
*

0 commit comments

Comments
 (0)