Comparing version 0.1.1 to 0.2.0
29
index.js
@@ -15,22 +15,29 @@ // git-tag | ||
var get = function(cb) { | ||
var get = function () { | ||
var cb; | ||
var args = ""; | ||
if (arguments.length <= 1) { | ||
cb = arguments[0]; | ||
} else { | ||
cb = arguments[1]; | ||
args = arguments[0]; | ||
} | ||
if (options.dir) { | ||
var cmd = 'git -C '+options.dir+' tag -l' | ||
}else{ | ||
var cmd = 'git tag -l' | ||
var cmd = 'git -C ' + options.dir + ' tag -l ' + args | ||
} else { | ||
var cmd = 'git tag -l ' + args | ||
} | ||
if (!options.localOnly) { | ||
if (options.dir) { | ||
cmd = 'git -C '+options.dir+' pull origin --tags; ' + cmd | ||
}else{ | ||
cmd = 'git pull origin --tags; ' + cmd | ||
cmd = 'git -C ' + options.dir + ' pull origin --tags ' + args + ";" + cmd | ||
} else { | ||
cmd = 'git pull origin --tags ' + args + ";" + cmd | ||
} | ||
} | ||
exec(cmd, function(err, res){ | ||
exec(cmd, function (err, res) { | ||
if (err) return callback(cb, err, []) | ||
res = res.replace(/^\s+|\s+$/g,'').split(/\n/) | ||
res = res.replace(/^\s+|\s+$/g, '').split(/\n/) | ||
try { | ||
res = res.sort(semver.compare) | ||
} catch(e) {} | ||
} catch (e) { } | ||
callback(cb, err, res) | ||
@@ -37,0 +44,0 @@ }) |
{ | ||
"name": "git-tag", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "simply command 'git tag' wrapper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,3 +57,3 @@ # git-tag | ||
}) | ||
gitTag.all(function(err, res){ | ||
gitTag.all("--merged", function(err, res){ | ||
console.log(err, res) // >> null, ['0.0.2015'] | ||
@@ -60,0 +60,0 @@ }) |
var assert = require('assert') | ||
var gitTag = require('../')({localOnly:true,dir:'../.git'}) | ||
var gitTag = require('../')({localOnly:true,dir:'.git'}) | ||
var async = require('async') | ||
@@ -31,5 +31,19 @@ | ||
}, | ||
// get all tags with correct argument | ||
function (next) { | ||
gitTag.all("--merge", function (res) { | ||
assert.ok(toString.apply(res) === '[object Array]') | ||
next() | ||
}) | ||
}, | ||
// get all tags with incorrect argument | ||
function (next) { | ||
gitTag.all("--foobar", function (err, res) { | ||
assert.ok(err) | ||
next() | ||
}) | ||
}, | ||
// get all tags with 2 args | ||
function(next) { | ||
gitTag.all(function(err, res){ | ||
gitTag.all(function (err, res) { | ||
assert.ok(!err) | ||
@@ -42,5 +56,5 @@ assert.ok(toString.apply(res) === '[object Array]') | ||
function(next) { | ||
gitTag.latest(function(err, res){ | ||
gitTag.latest(function (err, res) { | ||
assert.ok(!err) | ||
assert.ok(res === invalidTag) | ||
assert.ok(res === tagname) | ||
next() | ||
@@ -59,3 +73,3 @@ }) | ||
function(next) { | ||
gitTag.latest(function(res){ | ||
gitTag.latest(function (res) { | ||
assert.ok(res === tagname) | ||
@@ -62,0 +76,0 @@ next() |
7607
171