Skip to content

Commit 1a3b1fa

Browse files
mattyclarksonJohn Haley
authored andcommitted
Added the repository.createLightweightTag
This is a simple function that can create a new lightweight tag in a repository. The same can be acheived by creating a new reference in `/refs/tags/` but this performs libgit2 validation of tag names. ``` return repository.createLightweightTag(oid, 'foobar') .then(function(tag) { // The new tag is returned }); ```
1 parent 29c6083 commit 1a3b1fa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/repository.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,27 @@ Repository.prototype.createTag = function(oid, name, message, callback) {
292292
});
293293
};
294294

295+
/**
296+
* Creates a new lightweight tag
297+
*
298+
* @async
299+
* @param {String|Oid} String sha or Oid
300+
* @param {String} name the name of the tag
301+
* @return {Reference}
302+
*/
303+
Repository.prototype.createLightweightTag = function(oid, name, callback) {
304+
var repository = this;
305+
306+
return Commit.lookup(repository, oid)
307+
.then(function(commit) {
308+
// Final argument is `force` which overwrites any previous tag
309+
return Tag.createLightweight(repository, name, commit, 0);
310+
})
311+
.then(function() {
312+
return Reference.lookup(repository, "refs/tags/" + name);
313+
});
314+
};
315+
295316
/**
296317
* Retrieve the tag represented by the oid.
297318
*

0 commit comments

Comments
 (0)