Skip to content

Commit

Permalink
Fix conflicter to allow skipping
Browse files Browse the repository at this point in the history
Fix #725
  • Loading branch information
SBoudrias committed Dec 21, 2014
1 parent f3e0f7a commit 3249643
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ actions.bulkDirectory = function directory(source, destination, process) {
// until next tick, which resets the source root on remote
// bulkCopy operations
source = path.join(this.sourceRoot(), source);
this.conflicter.checkForCollision(destination, null, function (err, config) {
this.conflicter.checkForCollision(destination, null, function (err, status) {
// create or force means file write, identical or skip prevent the
// actual write.
if (/force|create/.test(config.status)) {
if (/force|create/.test(status)) {
this._directory(source, destination, process, true);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,13 @@ Base.prototype.getCollisionFilter = function () {
return function checkForCollisionFilter(output) {
var done = this.async();

self.conflicter.checkForCollision(output.path, output.contents, function (err, config) {
self.conflicter.checkForCollision(output.path, output.contents, function (err, status) {
if (err) {
done(false);
return self.emit('error', err);
}

if (!/force|create/.test(config.status)) {
if (!/force|create/.test(status)) {
return done('Skip modifications to ' + output.path);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/conflicter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Conflicter.prototype.resolve = function (cb) {
self.collision(conflict.file, function (status) {
// Remove the resolved conflict from the queue
_.pull(self.conflicts, conflict);
conflict.callback(null, { status: status });
conflict.callback(null, status);
next();
});
};
Expand Down
20 changes: 19 additions & 1 deletion test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,26 @@ describe('generators.Base', function () {
}.bind(this));
});

it('does not pass config file to conflicter', function (done) {
it('allow skipping file writes to disk', function (done) {
var action = { action: 'skip' };
var filepath = path.join(__dirname, '/fixtures/conflict.js');
assert(fs.existsSync(filepath));
this.TestGenerator.prototype.writing = function () {
this.fs.write(filepath, 'some new content');
};
var env = yeoman.createEnv([], { 'skip-install': true }, new TestAdapter(action));
var testGen = new this.TestGenerator([], {
resolved: 'generator/app/index.js',
namespace: 'dummy',
env: env
});
testGen.run(function () {
assert.equal(fs.readFileSync(filepath, 'utf8'), 'var a = 1;\n');
done();
}.bind(this));
});

it('does not pass config file to conflicter', function (done) {
this.TestGenerator.prototype.writing = function () {
fs.writeFileSync(this.destinationPath('.yo-rc.json'), '{"foo": 3}');
fs.writeFileSync(path.join(userHome, '.yo-rc-global.json'), '{"foo": 3}');
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/conflict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = 1;

0 comments on commit 3249643

Please sign in to comment.