From 8aefba6b11d890064ad2e0e883edffe860bc659f Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 09:33:06 +0000 Subject: [PATCH 01/10] Added git_tag_create* descriptors The `git_tag_create*` functions expect there to be a Oid pointer as the first parameter. --- generate/input/descriptor.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 6c4da260c..394abeee8 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1605,6 +1605,39 @@ "git_tag_foreach": { "ignore": true }, + "git_tag_create": { + "args": { + "oid": { + "isReturn": true + } + }, + "return": { + "isErrorCode": true + }, + "isAsync": true + }, + "git_tag_create_lightweight": { + "args": { + "oid": { + "isReturn": true + } + }, + "return": { + "isErrorCode": true + }, + "isAsync": true + }, + "git_tag_annotation_create": { + "args": { + "oid": { + "isReturn": true + } + }, + "return": { + "isErrorCode": true + }, + "isAsync": true + }, "git_tag_list": { "args": { "tag_names": { From 0e10205ea25eb0f42b200ff6f7027c70c8735a49 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 17:34:36 +0000 Subject: [PATCH 02/10] Added git_tag_delete descriptor --- generate/input/descriptor.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index 394abeee8..e7ea3f3de 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1657,6 +1657,12 @@ "isReturn": true } } + }, + "git_tag_delete": { + "return": { + "isErrorCode": true + }, + "isAsync": true } } }, From 91b8b0c630c523f921d92df406d7325e9e70f939 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 13:20:24 +0000 Subject: [PATCH 03/10] Ignore git_tag_create_frombuffer I'm not sure of how this should be handled at the moment. It will need a similar descriptor as `git_tag_create` but maybe extra data defining `buffer`. --- generate/input/descriptor.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generate/input/descriptor.json b/generate/input/descriptor.json index e7ea3f3de..507a82a23 100644 --- a/generate/input/descriptor.json +++ b/generate/input/descriptor.json @@ -1616,6 +1616,9 @@ }, "isAsync": true }, + "git_tag_create_frombuffer": { + "ignore": true + }, "git_tag_create_lightweight": { "args": { "oid": { From 24e06c60fade65c549c239e30492153c9c17d597 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 17:37:18 +0000 Subject: [PATCH 04/10] repository.deleteTagByName API A good convenience function for deleting a tag --- lib/repository.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/repository.js b/lib/repository.js index 4034ca458..b5153b682 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -314,6 +314,20 @@ Repository.prototype.getTagByName = function(name, callback) { }, callback); }; +/** + * Deletes a tag from a repository by the tag name. + * + * @async + * @param {String} Short or full tag name + */ +Repository.prototype.deleteTagByName = function(name) { + var repository = this; + + name = ~name.indexOf("refs/tags/") ? name.substr(10) : name; + + return Tag.delete(repository, name); +}; + /** * Instantiate a new revision walker for browsing the Repository"s history. * See also `Commit.prototype.history()` From 436954421c98e9ff302feb941aa62192799e1ab1 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 13:48:31 +0000 Subject: [PATCH 05/10] 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 }); ``` --- lib/repository.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/repository.js b/lib/repository.js index b5153b682..6589ae570 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -268,6 +268,30 @@ Repository.prototype.getTree = function(oid, callback) { }, callback); }; +/** + * Creates a new annotated tag + * + * @async + * @param {String|Oid} String sha or Oid + * @param {String} name the name of the tag + * @param {String} message the description that will be attached to the + * annotated tag + * @return {Tag} + */ +Repository.prototype.createTag = function(oid, name, message, callback) { + var repository = this; + var signature = repository.defaultSignature(); + + return Commit.lookup(repository, oid) + .then(function(commit) { + // Final argument is `force` which overwrites any previous tag + return Tag.create(repository, name, commit, signature, message, 0); + }) + .then(function(tagOid) { + return repository.getTag(tagOid, callback); + }); +}; + /** * Retrieve the tag represented by the oid. * From b54489877166e524f5b0c1899066bb617462ef7d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 13:50:32 +0000 Subject: [PATCH 06/10] Allow overriding the tag name in the testTag function This allows new tags to be created and tested --- test/tests/tag.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests/tag.js b/test/tests/tag.js index 1f2ffca00..7e4c4c986 100644 --- a/test/tests/tag.js +++ b/test/tests/tag.js @@ -15,8 +15,8 @@ describe("Tag", function() { var commitPointedTo = "32789a79e71fbc9e04d3eff7425e1771eb595150"; var tagMessage = "This is an annotated tag\n"; - function testTag(tag) { - assert.equal(tag.name(), tagName); + function testTag(tag, name) { + assert.equal(tag.name(), name || tagName); assert.equal(tag.targetType(), Obj.TYPE.COMMIT); assert.equal(tag.message(), tagMessage); From 189854f1d80832ca4ee39ae73d4a61d1e95ac698 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 19:24:07 +0000 Subject: [PATCH 07/10] Unit tests for Repository.createTag --- test/tests/tag.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/tests/tag.js b/test/tests/tag.js index 7e4c4c986..94e863caa 100644 --- a/test/tests/tag.js +++ b/test/tests/tag.js @@ -7,6 +7,8 @@ describe("Tag", function() { var Tag = require(local("../../lib/tag")); var Obj = require(local("../../lib/object")); var Oid = require(local("../../lib/oid")); + var Reference = require(local("../../lib/reference")); + var Promise = require("nodegit-promise"); var reposPath = local("../repos/workdir/.git"); var tagName = "annotated-tag"; @@ -75,4 +77,36 @@ describe("Tag", function() { assert.equal(tagNames.length, 1); }); }); + + it("can create a new annotated tag in a repo and delete it", function() { + var oid = Oid.fromString(commitPointedTo); + var name = "created-annotated-tag"; + var repository = this.repository; + + return repository.createTag(oid, name, tagMessage) + .then(function(tag) { + testTag(tag, name); + }) + .then(function() { + return repository.createTag(oid, name, tagMessage); + }) + .then(function() { + return Promise.reject(new Error("should not be able to create the '" + + name + "' tag twice")); + }, function() { + return Promise.resolve(); + }) + .then(function() { + return repository.deleteTagByName(name); + }) + .then(function() { + return Reference.lookup(repository, "refs/tags/" + name); + }) + .then(function() { + return Promise.reject(new Error("the tag '" + name + + "' should not exist")); + }, function() { + return Promise.resolve(); + }); + }); }); From d0af083e1005c46271a2723c2ce735826b1cd147 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 13:51:52 +0000 Subject: [PATCH 08/10] 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 }); ``` --- lib/repository.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/repository.js b/lib/repository.js index 6589ae570..878052f13 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -292,6 +292,27 @@ Repository.prototype.createTag = function(oid, name, message, callback) { }); }; +/** + * Creates a new lightweight tag + * + * @async + * @param {String|Oid} String sha or Oid + * @param {String} name the name of the tag + * @return {Reference} + */ +Repository.prototype.createLightweightTag = function(oid, name, callback) { + var repository = this; + + return Commit.lookup(repository, oid) + .then(function(commit) { + // Final argument is `force` which overwrites any previous tag + return Tag.createLightweight(repository, name, commit, 0); + }) + .then(function() { + return Reference.lookup(repository, "refs/tags/" + name); + }); +}; + /** * Retrieve the tag represented by the oid. * From cb5ceecb69b60b8bc087cdb277d8f78e9fe25a2b Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 19:24:49 +0000 Subject: [PATCH 09/10] Unit testing for repository.createLightweightTag --- test/tests/tag.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/tests/tag.js b/test/tests/tag.js index 94e863caa..484e48f56 100644 --- a/test/tests/tag.js +++ b/test/tests/tag.js @@ -109,4 +109,39 @@ describe("Tag", function() { return Promise.resolve(); }); }); + + it("can create a new lightweight tag in a repo and delete it", function() { + var oid = Oid.fromString(commitPointedTo); + var name = "created-lightweight-tag"; + var repository = this.repository; + + return repository.createLightweightTag(oid, name) + .then(function(reference) { + return reference.target(); + }) + .then(function(refOid) { + assert.equal(refOid.toString(), oid.toString()); + }) + .then(function() { + return repository.createLightweightTag(oid, name); + }) + .then(function() { + return Promise.reject(new Error("should not be able to create the '" + + name + "' tag twice")); + }, function() { + return Promise.resolve(); + }) + .then(function() { + return repository.deleteTagByName(name); + }) + .then(function() { + return Reference.lookup(repository, "refs/tags/" + name); + }) + .then(function() { + return Promise.reject(new Error("the tag '" + name + + "' should not exist")); + }, function() { + return Promise.resolve(); + }); + }); }); From 54c83647f41bead8fb5507ae3883e3b06cd1e0e0 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 27 Feb 2015 19:09:29 +0000 Subject: [PATCH 10/10] Added futureHostile to .jshintrc This flag fixes up the fact that we are polyfilling `Promise`: ``` var Promise = require('nodegit-promise'); ``` --- .jshintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.jshintrc b/.jshintrc index ea2e2b7b1..5f5082b77 100644 --- a/.jshintrc +++ b/.jshintrc @@ -12,6 +12,7 @@ "unused": "vars", "undef": true, "validthis": true, + "futurehostile": true, "globals": { "global": true, "define": true,