From ed493d4031f99e5680352d19664a34628a6f407d Mon Sep 17 00:00:00 2001 From: Marcello de Sales Date: Sun, 16 Nov 2014 01:09:54 -0800 Subject: [PATCH 1/2] Issue #6: Git reset the bump commit when the tag already exists. 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. --- index.js | 31 +++++++++++++++++++++++++++++-- package.json | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 527b92c..9d7776b 100644 --- a/index.js +++ b/index.js @@ -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 = {} @@ -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) } diff --git a/package.json b/package.json index 9215b47..a46b492 100644 --- a/package.json +++ b/package.json @@ -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": { From cdee81397757d286d52728c7332a7caf2e31cb8d Mon Sep 17 00:00:00 2001 From: Marcello de Sales Date: Sun, 16 Nov 2014 12:50:51 -0800 Subject: [PATCH 2/2] Issue #6: Forgot to npm install --save gift in the last commit: Updating package.json --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a46b492..73a1b89 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,10 @@ "author": "Cezar \"ikari\" Pokorski ", "license": "BSD-2-Clause", "dependencies": { - "map-stream": "~0.1.0", + "gift": "^0.4.3-1", + "gulp-git": "~0.3.6", "gulp-util": "~2.2.14", - "gulp-git": "~0.3.6" + "map-stream": "~0.1.0" }, "devDependencies": { "gulp-bump": "~0.1.7",