Skip to content

Commit

Permalink
Issue ikari-pl#6: Git reset the bump commit when the tag already exists.
Browse files Browse the repository at this point in the history
This is performed by using the git module "gift" and not issuing
a git tag if it exists.

https://github.com/notatestuser/gift#reporesettreeish-options-callback

After this point, we just reset HEAD^.

*	modified:   index.js
- Implementing the steps to get the git repo, and the list of tags

*	modified:   package.json
- Bumping the version manually to 1.1.1.
  • Loading branch information
marcellodesales committed Nov 16, 2014
1 parent eb6ad30 commit ed493d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var map = require('map-stream'),
gutil = require('gulp-util'),
git = require('gulp-git')
git = require('gulp-git'),
gift = require('gift');

module.exports = function(opts) {
if(!opts) opts = {}
Expand All @@ -16,7 +17,33 @@ module.exports = function(opts) {
var json = JSON.parse(file.contents.toString()),
tag = opts.prefix+json[opts.key]
gutil.log('Tagging as: '+gutil.colors.cyan(tag))
git.tag(tag, 'tagging as '+tag, opts)

// gift is a full-fledge git plugin
var APP_DIR = process.env.PWD;
var repo = gift(APP_DIR);

// Retrieve all the existing tags
repo.tags(function(err, tags) {
// Collect their names
var tagNames = tags.map(function(tag) {
return tag.name;
});

// If it does not exist, we can tag safely.
if (tagNames.indexOf(tag) < 0) {
git.tag(tag, 'tagging as '+tag, opts);

} else {
// Revert the "bump" commit because the command would fail.
gutil.log("Tag " + gutil.colors.cyan(tag) + " exists! Revering commit...");
repo.reset("HEAD^", function(err) {
if (err) {
return cb(new Error(err));
}
});
}
});

cb(null, file)
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-tag-version",
"version": "1.1.0",
"version": "1.1.1",
"description": "Tag git repository with current package version",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ed493d4

Please sign in to comment.