1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var npm = require('../../')
4 var npmc = require.resolve('../../')
5 var osenv = require('osenv')
6 var path = require('path')
8 var rimraf = require('rimraf')
9 var mkdirp = require('mkdirp')
10 var which = require('which')
11 var util = require('util')
12 var spawn = require('child_process').spawn
16 , '--no-git-tag-version'
18 var pkg = __dirname + '/version-no-tags'
20 test("npm version <semver> without git tag", function (t) {
22 npm.load({ cache: pkg + '/cache', registry: common.registry}, function () {
23 which('git', function(err, git) {
24 function tagExists(tag, _cb) {
25 var child = spawn(git, ['tag', '-l', tag])
27 child.stdout.on('data', function(d) {
28 out += data.toString()
30 child.on('exit', function() {
31 return _cb(null, Boolean(~out.indexOf(tag)))
35 var child = spawn(git, ['init'])
36 child.stdout.pipe(process.stdout)
37 child.on('exit', function() {
38 npm.config.set('git-tag-version', false)
39 npm.commands.version(['patch'], function(err) {
40 if (err) return t.fail('Error perform version patch')
41 var testPkg = require(pkg+'/package')
42 if (testPkg.version !== '0.0.1') t.fail(testPkg.version+' !== \'0.0.1\'')
43 t.ok('0.0.1' === testPkg.version)
44 tagExists('v0.0.1', function(err, exists) {
45 t.equal(exists, false, 'git tag DOES exist')
46 t.pass('git tag does not exist')
55 test('cleanup', function(t) {
56 // windows fix for locked files
57 process.chdir(osenv.tmpdir())
65 mkdirp.sync(pkg + '/cache')
66 fs.writeFileSync(pkg + '/package.json', JSON.stringify({
68 name: "version-no-tags-test",
70 description: "Test for git-tag-version flag"