Skip to content

Commit

Permalink
fix(tar) don't read .gitignore when have .spmignore
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 22, 2014
1 parent 8f842e1 commit 818d93a
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
node_modules
coverage
build
.idea
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -6,3 +6,4 @@ node_modules/
.editorconfig
.travis.yml
.jshintrc
.idea
28 changes: 16 additions & 12 deletions lib/tar.js
Expand Up @@ -6,18 +6,6 @@ var path = require('path');
var fs = require('fs');
//var log = require('./log');

var myUid = process.getuid && process.getuid();
var myGid = process.getgid && process.getgid();

if (process.env.SUDO_UID && myUid === 0) {
if (!isNaN(process.env.SUDO_UID)) {
myUid = +process.env.SUDO_UID;
}
if (!isNaN(process.env.SUDO_GID)) {
myGid = +process.env.SUDO_GID;
}
}

exports.create = function(source, target, callback, noIgnore) {
function returnError(err) {
// don't call the callback multiple times, just return the first error
Expand Down Expand Up @@ -132,6 +120,22 @@ Packer.prototype.applyIgnores = function(entry, partial, entryObj) {
return Ignore.prototype.applyIgnores.call(this, entry, partial, entryObj);
};

Packer.prototype.addIgnoreFiles = function () {
var entries = this.entries
// if there's a .spmignore, then we do *not* want to
// read the .gitignore.
if (-1 !== entries.indexOf(".spmignore")) {
var i = entries.indexOf(".gitignore")
if (i !== -1) {
entries.splice(i, 1);
}
}

this.entries = entries;

Ignore.prototype.addIgnoreFiles.call(this);
};

Packer.prototype.emitEntry = function(entry) {
if (this._paused) {
this.once('resume', this.emitEntry.bind(this, entry));
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -24,14 +24,15 @@
"tar": "~1.0.0"
},
"devDependencies": {
"spy": "~0.1.0",
"ali.regenerator": "0",
"co-mocha": "0",
"coveralls": "2",
"istanbul-harmony": "0",
"ls-archive": "~1.0.2",
"mocha": "1",
"ali.regenerator": "0",
"rimraf": "2",
"should": "4",
"rimraf": "2"
"spy": "~0.1.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/tar/.npmignore
@@ -0,0 +1,2 @@
test

2 changes: 2 additions & 0 deletions test/fixtures/tar/.spmignore
@@ -0,0 +1,2 @@
test

2 changes: 2 additions & 0 deletions test/fixtures/tar/gitignore
@@ -0,0 +1,2 @@
lib
test
Empty file added test/fixtures/tar/index.js
Empty file.
Empty file added test/fixtures/tar/lib/index.js
Empty file.
5 changes: 5 additions & 0 deletions test/fixtures/tar/package.json
@@ -0,0 +1,5 @@
{
"name": "test-ignore",
"version": "0.1.0",
"spm": {}
}
Empty file added test/fixtures/tar/test/index.js
Empty file.
37 changes: 37 additions & 0 deletions test/tar.test.js
@@ -0,0 +1,37 @@
'use strict';

require('should');
var join = require('path').join;
var archive = require('ls-archive');
var tar = require('../lib/tar');
var rimraf = require('rimraf').sync;
var rename = require('fs').renameSync;

describe('tar', function() {

var dir = join(__dirname, './fixtures/tar');
var tarfile = join(__dirname, './fixtures/tar.tar.gz');

beforeEach(function() {
rename(join(dir, 'gitignore'), join(dir, '.gitignore'));
});

afterEach(function() {
rename(join(dir, '.gitignore'), join(dir, 'gitignore'));
});

it('normal', function(done) {

tar.create(dir, tarfile, function(err, target) {

archive.list(target, function(err, files) {
files = files.map(function(f) {
return f.path;
});
files.should.be.eql(['index.js', 'lib/index.js', 'package.json']);
rimraf(tarfile);
done();
});
});
});
})

0 comments on commit 818d93a

Please sign in to comment.