Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Issue #6: Git reset the bump commit when the tag already exists. #7

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 4 additions & 3 deletions 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 All @@ -18,9 +18,10 @@
"author": "Cezar \"ikari\" Pokorski <[email protected]>",
"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",
Expand Down